Data Format¶
The devices transmit data to the cloud as per the attributes, measurement points, events, and services defined in the model. EnOS supports the data in both EnOS standard JSON format and custom format.
EnOS Standard Data Format¶
In general, we recommend to transmit data using the EnOS standard JSON format.
The sample codes below show the standard data format used for uploading data into the cloud:
{
"id": "123",
"version": "1.0",
"params": {
"measurepoints": {
"Power": {
"value": 1.0,
"quality": 9
},
"temp": 1.02,
"branchCurr": [
"1.02", "2.02", "7.93"
]
},
"time": 123456
},
"method": "thing.measurepoint.post"
}
The sample codes below show the standard data format used for issuing data from the cloud to devices:
{
"id": "123",
"version": "1.0",
"params": {
"temperature": 30.5
},
"method": "thing.service.measurepoint.set"
}
In the above-mentioned sample codes:
id
refers to the message ID.version
refers to the protocol version.The JSON arrays packaged by
params
refer to the data to be transmitted.method
refers to the request method.
The EnOS device protocol defines which format and by which topic the device transmits the data to the cloud. For more information, see MQTT-based Device Connection.
Custom Data Format¶
The JSON format-based data communication with the cloud is not suitable for the devices with lower configurations and limited resources or those with special requirements on networking traffic, or those that support custom data protocols. In these type of cases, there are two methods to onboard devices, via data parsing or using a protocol gateway.
Data Parsing (Deprecated)¶
For data parsing, you can pass the data to the cloud, and then the cloud runs the parsing scripts to convert the data into the JSON format defined by EnOS. When the cloud sends the control commands to the device, the scripts may also be used to convert the JSON format defined by EnOS into the binary data that the device is able to parse for issuing purpose.
For the devices that transmit the data by means of pass-through or in the custom format, you may compile scripts in the EnOS Cloud to parse the data from the devices. The parsing scripts support JavaScript-based development.
The EnOS parser provides the following capabilities.
Editing script online, and supports the validation of JavaScript syntax.
Upstream & downstream messaging simulation and debugging, and supports the viewing of simulation result.
Runtime environment after the publishing of script can be invoked for upstream & downstream messaging.
For more information, see Parsing Custom Format Data.
Protocol Gateway¶
For devices that only support custom data protocols or specific industry protocols, the raw data can be accessed through a custom protocol gateway, which can be converted into EnOS IoT JSON format or other formats required by downstream modules or applications.
The EnOS protocol gateway provides the following capabilities.
Two-way conversion of protocols, opening up more ways to connect device data to EnOS.
Dynamically generate assets in IoT Hub based on the device data specified by the protocol, eliminating the need to manually create assets in IoT Hub.
For more information, see Device Onboarding.