Despite its name, this is not a format tied to Connhex - your devices will still be compatible with any IoT platform, since the message format is simple JSON with some predetermined keys.
A message compliant to the Connhex JSON has the following structure:
Tags are the keys that will be indexed at the database level.
|m||yes||Object key to group all tags. If there's at least one tag, there must be this key and its corresponding value must contain all tags.|
|key1||no||Example key. Can be any string, and the corresponding value must be a string.|
|key2||no||Example key. Can be any string, and the corresponding value must be a string.|
A few notes:
- You can add as many keys as necessary, and each key can be any string (key1, key2 are just examples)
- Connhex will use these keys to create database columns - or equivalents
- The value corresponding to a tag key must be a string
Data fields will, as a matter of fact, be stored at the database level as data.
|keyA||no||Example key. Can be any string, and the corresponding value should be either a string or a number.|
|keyB||no||Example key. Can be any string, and the corresponding value should be either a string or a number.|
A few notes:
- You can add as many keys as necessary, and each key can be any string (keyA, keyB are just examples)
- For performance reasons, try to stick with single values - string, number, boolean, ... - corresponding to a data key. Avoid deeply nested structures if possible
|t||yes||Unix timestamp, in milliseconds.|
Tags or data?
When formatting a message according to Connhex JSON, one of the most difficult decisions is to choose between creating a tag or a data field for a given value to transmit.
Here are a few guidelines and best practices:
- if the value you need to transmit together with a given key is not a string, use a data field
- if user facing apps need to use a key to sort, filter or search, leverage tags for that key-value pair
- a tag field is heavier in terms of disk usage than a data field. Try to use tags only for fields that need to be used as filters, and use data fields for the rest.
Connhex JSON vs SenML
If your devices need to send multiple message types, you could be facing the choice between using Connex JSON and SenML.
As a rule of thumb:
- if you only need to send data from sensors, and all measurements are independent from each other, use SenML.
- if at least one message is different from a single measurement - or may be in the future - use Connhex JSON and format your message like the example below.
Connhex JSON for sensor measurements
Instead of using SenML for sensor measurements, you can structure messages according to Connhex JSON using name, unit and value as keys:
"t": 1645627703, // Unix timestamp in milliseconds
"value": 0 // Measurement as number
For example, the same measurement used to illustrate how to create a SenML message here would be represented as:
Standardizing your messages this way leaves room for further optimization - compressing messages on the edge would be one typical example.
Enough of the theory, it's time to see some actual messages that Connhex instances are receiving right now.
Example 1: fleet diagnostic
This message is used to register diagnostic data:
- license_plate and unit_type are tags, since a dashboard allows to aggregate diagnostic data by license plate and measuring unit type
- diagnostics, alarms and coordinates are data and there's a single level of nesting
Example 2: machining data
"customer": "Acme Inc.",
This message is used to register data about machining operations:
- job is a tag, since a mobile app needs to filter data by job type
- all other fields are registered as data. In this case customer and job_ref have not been deemed interesting to query against: if an app needs to retrieve all operations related to a certain customer, the customer key should become a tag.