Elecsys JSON-RBE Protocol Specification

Updated 7/6/2017

MQTT Protocol

MQTT has become an industry standard for IoT and Cloud publishing applications. It is a low bandwidth protocol for publish/subscribe over TCP/IP, with different levels of assurance for delivery. The protocol was originally designed for the specialized client devices and network types found in critical infrastructure SCADA and remote telemetry applications.  Important features of the protocol are :


The protocol has a very basic publish/subscribe verb set: CONNECT, DISCONNECT, PUBLISH, SUBSCRIBE, UNSUBSCRIBE, and an application-level keep-alive: PINGRequest and PINGResponse. There are also message acknowledgment verbs, which are used to manage the assured message delivery.

Overview of JSON RBE

The JSON RBE protocol is an application-level messaging protocol in the Elecsys Industrial Data Gateway (IDG) products, such as RediGate and Director. JSON RBE uses MQTT to publish report by exception (RBE) data and to indicate the health and communication status of the gateway and all attached field devices (RTUs, PLCs, flow meters, sensors, etc.). The gateway publishes RBE data using a Quality of Service of 0. This means that if an RBE publication is received when there is no active application subscribed, it will be discarded by the broker. This will prevent non-required messages building up at the broker.

The JSON RBE application protocol consists of several categories of activities:

  1. Connect to the broker
  2. Disconnect from the broker
  3. Publish RBE device data to a host application
  4. Accept device commands from a host application
  5. Accept gateway system control commands

Connection Sequence

On connection of a gateway to the MQTT broker, the sequence of publications is as follows:

The topic namespace and message structures for these messages are described in later sections.

Topic Namespace

All JSON RBE protocol messages originating from the gateway are published to the broker. The MQTT pub/sub mechanism requires that all messages contain a topic string, and an optional payload consisting of a stream of bytes. The Elecsys gateway JSON publisher allows for configurable topics to publish data and to subscribe for commands. The data topic should be configured according to the needs of the host application. Subscriptions ideally should allow for wildcards, so that a gateway can subscribe for only the data intended for itself or its attached devices.

Birth and Death Certificates

The JSON RBE protocol contains information about the communications status of the gateway and its field devices. A birth certificate will indicate that a device is now “ONLINE” using a JSON tag. The death certificate published on behalf of a device indicates that the device has gone “OFFLINE” using a JSON tag.

A gateway birth certificate will be issued each time the gateway makes an IP connection to a broker. A death certificate for the gateway (Last Will & Testament) will be lodged with the broker on initial connection. When the gateway MQTT connection terminates, the broker will publish this death certificate on behalf of the gateway. The payload of the gateway’s Last Will & Testament will be a string that has been configured for each gateway.

Data Publish Payload Format

An example JSON data payload for publishing data from a field device is:

{
   "d": {
   "gwName": "GatewayName",
   "devName": "FieldUnit",
   "BoolTag1": false,
   "BoolTag2": false,
   "00003": false,
   "00004": false,
   "AnaTag1": 0,
   "40002": 0,
   "FloatTag1": 123.456,
   "47002": "",
   "StringTag1": "This is a string value",
   "49002": "This is another string",
   "rtuIsAlive": true,
   "SeqNumb": 0
   }
}

Explanation of tags:

If a device changes from good to failed communication, a Device Publish message will be published with the next sequence number and rtuIsAlive = false, such as:

{
       "d": {
       "gwName": "GatewayName",
       "devName": "FieldUnit",
       "rtuIsAlive": false,
       "SeqNumb": 10
       }
}


Data Subscription Payload Format

The JSON payload for Device Command messages published from a host to an end device is the same as the payload for the Device Data. Subscriptions for Device Command messages are optional. The Device Command values can either use the tag name (if configured) or register address of the registers to be written to. Only the tags written to need to be included in the Device Command message. The other tags in Device Publish messages (gwName, devName, rtuIsAlive, SeqNumb) can be omitted, or they will be ignored by the receiving device, assuming it has no registers configured with those tag names.

An example subscription JSON data payload is:

{
   "d": {
   "BoolTag1": false,
   "40002": 123
   }
}

Example JSON Data Subscription

Consider if your RediGate had the following topics configured in a JSON RBE → Topic Rules table:

The RediGate would publish data on the RG/${GATEWAY}/${CHAN}_${DEV}/RBE topic with the payload described above in the JSON-RBE MQTT Payload Format#Data Publish Payload Format section. The topic would be built using the values corresponding to the ${variable}'s, described below:

In the example above, if you wanted to publish the integer value "12345" data back to a data register named "IntValue" in VirtualRW Unit 4 (name = VirtualRW):


you would send this payload:

{"d": {"IntValue": 12345}}

to this topic:

RG/RG-120C/Channel15_VirtualRW/CMD


Gateway Birth Payload Format

When the gateway first connects to the MQTT broker, it will publish its birth message with sequence number of zero. This includes a number of “metrics” with gateway system information, such as those listed below:

{
       "d": {
       "gwName": "GatewayName",
       "Tarball_Date": "2017-06-16-0900",
       "MQttBroker_IP": "127.0.0.1",
       "MQtt_NumbConnects": 2,
       "Numb_Devices": 3,
       "Device[0]_Name": "Modbus-1",
       "Device[1]_Name": "Virtual",
       "Device[2]_Name": "VirtualRTU7",
       "ACE_Config_XML_Info": "469d14e029131bf930b0147175206344 /usr/director/config/BlueMix-JSON_Demo1.xml.gz",
       "ACE_Config_UFF_Info": "8ce078a1a3360e9ea5d2cd7768193c11 /usr/director/config/RG-110E.uff",
       "Gateway_Uptime": " 00:00:21 up 38 min, load average: 1.33, 1.00, 0.77",
       "Free_Memory": "Mem: 253988 25296 228692 0 0",
       "Disk_Usage": "ubi0:rootfs 57476 21716 35760 38% /",
       "Gateway_Time": "1999-11-30-00:00:21.896",
       "MQtt_Msgs_Recv": 3,
       "MQtt_Msgs_Sent": 3,
       "Connection": "ONLINE",
       "SeqNumb": 0
       }
}

Gateway Subscription Payload Format

The gateway may subscribe to system service requests using a Gateway Subscription topic. These subscriptions are optional, but are needed in order to receive gateway-level system commands or device-level commands. A host application may send a command to the RediGate using a JSON packet with integer value for SystemCommand. For example:

General System Command

{
       "d:" {
       "SystemCommand": 2
       }
}

(or as a single line, with white space removed)

{"d:"{"SystemCommand":2}}


The value of the SystemCommand tag should be:

            1 = Gateway reboot.

            2 = Resend all data from all devices – issue full gateway birth and device data update, but do not reset SeqNumb to zero.

            6 = Set system time (include SystemTime variable; see below).

            7 = Next MQTT server address – disconnect from current IP address and use the next address in the list, or reconnect to the same server if only one is configured.

            9 = Force gateway reconfigure – stop gateway software, check for software or configuration update, and restart (may result in a full gateway reboot).


Payload for System Command 6 (set system time)

{
       "d:" {
       "SystemCommand": 6,
       "SystemTime": "2017-06-26T17:24:36.162Z"
       }
}

The SystemTime variable should be set to UTC time in ISO-8601 format, as shown. In NodeRED, the methods .toJSON() or .toISOString() will convert Date() to ISO format.

Historical Data Payload

When using the store and forward feature on the RediGate, the JSON-RBE object will publish the historical data in a different format to distinguish the historical data from the normal "report-by-exception" data. Data is published based on the RTU name (or devName), and is organized underneath timestamps corresponding to when the data was stored. Timestamps for data are given in UTC time reference. The payload below shows a historical payload that was published for a gateway named "RediGate120E" that contained an RTU/Device named "RemoteDevice1":

{
"gwName":"RediGate120E",
"devName":"RemoteDevice1",
"SeqNumb":0,
"h": {

"2017-09-06T14:17:47.000Z": {
"Second": 46,
"SinFunc": -0.4440860
},
"2017-09-06T16:22:05.000Z": {
"Hour": 11,
"Minute": 22,
"Second": 1,
"SinFunc": -0.2794150
},
"2017-09-06T16:22:18.000Z": {
"Second": 16,
"SinFunc": 0.9835880
},
"2017-09-06T16:22:33.000Z": {
"Second": 31,
"SinFunc": -0.6020240
},
"2017-09-06T16:22:48.000Z": {
"Second": 46,
"SinFunc": -0.4440860
},
"2017-09-06T16:23:03.000Z": {
"Minute": 23,
"Second": 1,
"SinFunc": -0.2794150
},
"2017-09-06T16:23:18.000Z": {
"Second": 16,
"SinFunc": 0.9835880
},
"2017-09-06T16:23:33.000Z": {
"Second": 31,
"SinFunc": -0.6020240
},
"2017-09-06T16:23:48.000Z": {
"Second": 46,
"SinFunc": -0.4440860
}
}
}