MQTT Topic Names
- Last UpdatedAug 10, 2017
- 2 minute read
Items subscribed to an MQTT broker are known as topics. MQTT data sources use topic names for sending and receiving messages. A topic name can be divided into multiple topic levels. Each level is separated by a forward slash (/). Wild cards are not supported for MQTT topic names in this release.
The following rules apply to topic names:
-
Must be at least once character in length
-
Names are case sensitive
-
Space character is valid and can be included
-
Names can include a leading or trailing forward slash, but the forward slash counts as an identifier (/a, a/ and a are all different topic names)
-
'/' is a valid topic name
-
Topic names cannot include the null character (U+0000)
-
Topic names are UTF-8 encoded strings. The maximum encoded length is 65535 bytes
Note: In general, MQTT supports the usage of "+" as a single level wild card and "#" as a multi-level wild card. However, the Wonderware MQTT driver does not currently support usage of wild cards.
Syntax Example
site/area1/mixer4/valve/input
Using JSON Strings
Data messages should be in string format. The string can be formatted as a JSON key value pair, which will be detected automatically. JSON messages are parsed by the driver to allow the extraction of each key value pair as attributes of an object.
For example, the field device from a pump station transmits a message that includes location, pump running status, oil pressure, and maintenance data. The MQTT topic for this message is Field/FS785/Status. The payload for this message could use a JSON formatted message, such as:
{"lat":32.95646, "lon":-96.82275, "Pump_running":1, “Oil_Press”:67.23, “Maintenance”:"Last Maintenance Dec 14-2015"}
An application could subscribe to any of the following topics:
-
Field/FS785/Status
-
Field/FS785/Status.lat
-
Field/FS785/Status.lon
-
Field/FS785/Status.Pump_Running
-
Field/FS785/Status.Oil_Press
-
Field/FS785/Status.Maintenance
For OI Gateway G-2.0 and above, the MQTT subscriber supports embedded JSON strings, as well as strings at multiple nested levels (objects and arrays). Refer the examples of possible JSON string forms and the referenced values below.
Example 1: If TagX receives a JSON string of form { “Value1”: 1, “Value2”:2}
Values in the JSON string are referenced as follows:
|
Tag Reference |
Value |
|
TagX |
{ “Value1”: 1, “Value2”:2} |
|
TagX.Value1 |
1 |
|
TagX.Value2 |
2 |
Example 2: If TagA receives a JSON string of form { “Value1”: 1, “Value2”:{ “value3”: 2, “value4”: 3 }, “Value5”: [ 5, 6] }
Values in the JSON string are referenced as follows:
|
Tag Reference |
Value |
|
TagA |
{ “Value1”: 1, “Value2”:{ “value3”: 2, “value4”: 3 }, “Value5”: [ 5, 6]} |
|
TagA.Value1 |
1 |
|
TagA.Value2 |
{ “value3”: 2, “value4”: 3 } |
|
TagA.Value2.value3 |
2 |
|
TagA.Value2.value4 |
3 |
|
TagA.Value5 |
[5,6] |
|
TagA.Value5[0] |
5 |
|
TagA.Value5[1] |
6 |
Example 3: If TagA receives a JSON string of form [ “stringValue1”, “stringValue2”]
Values in the JSON string are referenced as follows:
|
Tag Reference |
Value |
|
TagS |
[ “stringValue1”, “stringValue2”] |
|
TagS.[0] |
stringValue1 |
|
TagS.[1] |
stringValue2 |