To integrate Helium Concolse with ThingsBoard, we need to use “MQTT Integration” on Helium. Also, a central MQTT Broker is required.
Overall Flow:
Steps:
MQTT Integration: in this manual, we use a public MQTT Broker (HIVEMQ.com)
- Broker: broker.hivemq.com
TCP Port: 1883
Add new Integration (MQTT) in helium console:
Choose the MQTT option:
In the endpoint field, enter this in case of HIVEMQ:
mqtt://broker.hivemq.com:1883
And in uplink/downlink topic create unique topic structure.
In our case, we are using ‘helium/choovio’ as an example, but you need to create unique topics i-e ‘myproject/xyz/{{device_id}}/tx’ or ‘myproject/{{device_id}}/tx’.
2. We need to create a custom function for each type of sensor. You can find functions/decoders code on the vendor website or check this link for available Helium Console decoders:
https://github.com/helium/console-decoders
Here is the code for Dragino LDS02 LoRaWAN Door Sensor
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var value=(bytes[0]<<8 | bytes[1])&0x3FFF;
var bat=value/1000;//Battery,units:Vvar door_open_status=bytes[0]&0x80?1:0;//1:open,0:close
var water_leak_status=bytes[0]&0x40?1:0;var mod=bytes[2];
var alarm=bytes[9]&0x01;if(mod==1){
var open_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
var open_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
if(bytes.length==10 && 0x07>bytes[0]< 0x0f)
return {
BAT_V:bat,
MOD:mod,
DOOR_OPEN_STATUS:door_open_status,
DOOR_OPEN_TIMES:open_times,
LAST_DOOR_OPEN_DURATION:open_duration,
ALARM:alarm
};
}
else if(mod==2)
{
var leak_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
var leak_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
if(bytes.length==10 && 0x07>bytes[0]< 0x0f)
return {
BAT_V:bat,
MOD:mod,
WATER_LEAK_STATUS:water_leak_status,
WATER_LEAK_TIMES:leak_times,
LAST_WATER_LEAK_DURATION:leak_duration
};
}
else if(mod==3)
if(bytes.length==10 && 0x07>bytes[0]< 0x0f)
{
return {
BAT_V:bat,
MOD:mod,
DOOR_OPEN_STATUS:door_open_status,
WATER_LEAK_STATUS:water_leak_status,
ALARM:alarm
};
}
else{
return {
BAT_V:bat,
MOD:mod,
};
}
}
3. We should create flows that connect each sensor to the MQTT Broker, passing through its relevant custom function in ‘Flows’.
(You can find functions/decoders code from the vendor website)
4. Now we need to do ThingsBoard Integration with this MQTT broker to receive messages from the Helium Console and also need to create data converters (only uplink if you need to receive sensors data, in case of controlling devices, you will need downlink as well)
- Create Uplink Converter
Add the code:
Next, we need to add the uplink converter code. An example javascript code is given.
var data = decodeToJson(payload);
var deviceName= data[‘name’];
var deviceType=default;
var decodedpayload=data[‘decoded’][‘payload’];
var device_id=data[‘id’];
decodedpayload.device_id=device_id;var result = {
deviceName: deviceName,
deviceType: deviceType,
groupName:’Helium Devices’,
telemetry:decodedpayload
};function decodeToString(payload) {
return String.fromCharCode.apply(String, payload);
}function decodeToJson(payload) {
var str = decodeToString(payload);
var data = JSON.parse(str);
return data;
}
return result;
Code Explanation:
The data coming from Helium is in JSON format. In that message, we only need to pick decoded data.
Second, in the above code, we also pick the device name and ID from the message.
- Create Integration on ThingsBoard.
We need to input ur broker endpoint and port (HIVEMQ) and select the uplink which you just created (no need for a downlink for this guide)
In the topic filter, you will need to add the topic you created on Helium (the topic ended with rx).
You will now see newly created devices when data is received and telemetry. (next part is to make your dashboards and rule engine)