Introduction
This article explains the decoder feature and how to create a decoder script.
Decoder fonction
The decoder ingests messages coming from the things connected to the IoT Pilot Things VPN. The decoder script returns the measures decoded from the messages.
The decoder fonction is part of Pilot Things sensor Plug and Play mecanism.
Modify a Decoder script
Here are the step to modify a decoder script:
Step 1: Select a product in the catalog
Click on "Edit product"
Step 2: Edit decoder
On the edit page you can modify the decoder script. There are 2 cases :
Case 1: There is no decoder associate with that product
In that case you have to create a custom model before going forward. Once created select it in the list.
Case 2: There is already a decoder script associated to that product
Click on "Click to edit" to overwrite your decoder. The original decoder script is not lost. Simply click on "Reset" to revert.
Now that the model is selected you can create your decoder script. The decoder script is in plain Javascript. No external libraries are available.
The messages ingested into the decoder contain the following data:
Data | Description |
message.payload | Raw message data sent by the things |
message.topic | value is payload |
message.timestamp | message timestamp in Unix Epoc Time format |
message.metadata | additional information specific of the sensor protocol |
message.latitude | latitude coordinate of the things when the message was sent |
message.longitude | longitude coordinate of the things when the message was sent |
Once your decoder is done, click on the "save" button
step 3: test your decoder script
You can test your decoder script with a test message. Edit the values of the data and click on the "check" button.
Decoder script sample
This sample is for a temperature sensor. The associated model have an outside_temperature attribute.
The sample decoder script is:
function decodeMessage(message){
if(message.payload && message.topic === 'payload') {
var data = message.payload;
if(data !== undefined && data !== null && data !== '') {
return {outside_temperature : parseInt(data.substring(0,2), 16)};
}
}
}
Comments
0 comments
Please sign in to leave a comment.