Data Formats for TANI MQTT Implementation

Binary

The Binary format is used when higher performance or shorter network frames are needed.

For MQTT 5: The Payload Format Indicator is always 0 (Binary), except if the PLC data type is "String", for which it is 1 (String). The Content Type is a textual representation of the PLC data type, optionally followed by a comma separated list of PLC data type flags.

For MQTT 3.1/3.1.1: The data type can not be transferred using this protocol. Either configure the type on all systems equal or use one of the other protocol options.

Encoding

Examples

Note: all examples are given as hexdump.

Numeric value (42)

2A 00

Bit-Array (1, 0, 1, 0)

0A

Structure (First: int = 1, Second: String = "String Value")

01 00 00 00 04 00 00 00 53 74 72 69 6E 67 20 56 61 6C 75 65

JSON

The JSON data format is used to transfer data to/from systems that have difficulties with binary data. It consists of a JSON objects with the following properties.

For MQTT 5: The Payload Format Indicator is always 1 (String), the Content Type is "application/json"

Properties

Examples

Numeric value 42

{
  "Type": "Uint16",
  "Value": (42)
}

Bit-Array (1, 0, 1, 0)

{
  "Type": "Boolean",
  "Value": [
    true,
    false,
    true,
    false
  ]
}

Structure (First: int = 1, Second: String = "String Value")

{
  "Type": "Structure",
  "StructureName": "MyValues",
  "Value": {
    "First": 1,
    "Second": "String Value",
  }
}

XML

The XML data format is used to transfer data to/from systems that can't handle binary or JSON data. It recreates the JSON data described above as XML.

For MQTT 5: The Payload Format Indicator is always 1 (String), the Content Type is "text/xml"

JSON to XML mapping

Properties

See the JSON data described above.

Examples

Numeric value (42)

<o>
  <s n="Type">Uint16</s>
  <i n="Value">42</i>
</o>

Bit-Array (1, 0, 1, 0)

<o>
  <s n="Type">Boolean</s>
  <a n="Value">
    <t/>
    <f/>
    <t/>
    <f/>
  </a>
</o>

Structure (First: int = 1, Second: String = "String Value")

<o>
  <s n="Type">Structure</s>
  <s n="StructureName">MyValues</s>
  <o n=Value>
    <i n="First">1</i>
    <s n="Second">String Value</s>
  </o>
</o>

Data Types

Data Type list

NameMeaning
BooleanBinary value (true or false)
SByte, Int16, Int32, Int64Signed integers of 1, 2, 4 or 8 bytes length
Byte, UInt16, UInt32, UInt64Unsigned integers of 1, 2, 4 or 8 bytes length
Float, DoubleFloating point values of 4 or 8 bytes length
StringCharacter String
DateTimeTimestamp with date and time
StructureStructured data
EnumerationEnumerated data
LocalizedTextString with multiple possible translations

Data Type flags

FlagMeaning
BigEndianData is in big endian (most-significant byte first) order
LittleEndianData is in little endian (least-significant byte first) order. Note: only one of LittleEndian and BigEndian should be specified.
BitArrayLen1, BitArrayLen2, ... BitArrayLen7Indicate the number of valid bits in the last byte of a bit array. Not specifying one of these makes all 8 bits valid.