MQTT data payloads may contain the following fields.
The MQTT object sent to the portal should be a JSON object, either in a single layer (i.e. not nested) or two-layer (nested). The following formats are valid.
The following format is acceptable:
{ "timestamp": 1469626599000, "deviceId": "abc123", "switch": 1, "uses": 650 }
The white space and newlines are shown above for clarity but can be omitted.
You can use an object called "data", like this:
{ "timestamp": 1469626599000, "deviceId": "abc123", data { "switch": 1, "uses": 650 } }
Again, white space and newlines can be omitted.
Multiple payloads in the format above can be sent at once like this:
[ { "timestamp": 1469626599000, ... }, { "timestamp": 1469626600000, ... } ]
You don't need to include the device ID in the incoming MQTT data; this is identified from the topic.
Incoming data can optionally contain a timestamp in Unix microtime format (number of milliseconds since 1 January 1970 00:00:00UTC). If specified, denotes the time of the data reading (from a sensor, for example).
Example:
{ "timestamp": 1469626599000 ... }
This allows data to be batched up, and several readings send in one batch. If not specified, the portal will assume the data relates to the time at which it was received.
Can be 0 or 1, true or false.
Example:
{ "switch": 1 }
Can be any integer number.
Example:
{ "uses": 650 }
It is possible for data to be sent from an asset as an integer and then a factor applied (e.g. x0.001 to divide by 1,000). The factor can be determined on the Asset Type and the specific field in question.
Can be any floating-point number.
Example:
{ "temperature": 21.2 }
Can be a latitude and longitude.
Example:
{ "lat": 51.491151, "lon": -1.087291 }
It is not necessary to use the names "lat" and "lon" as in the example, but the fields must correspond to the field name codes in the Asset Type.
Can be a string of up to 256 characters in length.
Example:
{ "message": "Here is the message." }
Data seen in a message is only stored by Assetwolf if the field name exists in the Schema of the Asset whose ID is specified.
In other words, if the field referenced in the incoming JSON object isn't in the schema, the data for that field will be ignored.
The device may send either the complete field name, or a shortened "alias" form of the name. For example, here the field ledstatus
has an alias of led
, and so other can be used in the JSON object.
To set this up, go to the schema for the type of asset in question, and simply edit it to add the short alias.