Metrika
Ivy Knob

ThingsBoard and LoraServer (ChirpStack) integration example

ThingsBoard and LoraServer (ChirpStack) integration example

There are no examples in the internet yet about integration of two popular open source solutions: ThingsBoard and ChirpStack (prev. LoraServer).

ThingsBoard is one of the most popular and supported open source IoT platforms. It's built with Java as monolithic app in the beginning, but right now team of developers converts it to microservices architecture to allow scaling. ThingsBoard have flexible support of different storages for timeseries data: SQL (PostgreSQL) or noSQL (Cassandra). It's great solution if you want to use IoT Platform. ThingsBoard uses internal MQTT server for components interconnections.

ChirpStack (prev. LoraServer) is scaleable solution for building LoraWAN networks. It's build with Go language and each component is independent. ChirpStack (prev. LoraServer) uses external MQTT server for components interconnection. We recommend to use VerneMQ running on 1884 port.

Problem

ThingsBoard uses internal MQTT broker and its not convenient to use it with ChirpStack (prev. LoraServer): management process is not trivial. Because of this, it's better to use external MQTT server.

But how to make connection between two brokers?

Solution

Solution is to use ThingsBoard Gateway (tb-gateway). It is Java application that supports multiple sources of information and sends to ThingsBoard.

Step 1. Create new device as Gateway in the ThingsBoard dashboard. Copy access token and paste to tb-gateway config. Restart tb-gateway.

Step 2. In the dashboard click on the gateway and go to the extensions tab. Click import button and use this file as a template. Make sure to look for "Status: Sync"

[{
"id": "mqtt",
"type": "MQTT",
"configuration": {
"brokers": [{
"host": "localhost",
"port": 1884,
"ssl": false,
"retryInterval": 3000,
"credentials": {
"type": "basic",
"username": "username",
"password": "password"
},
"mapping": [{
"topicFilter": "application/+/device/+/rx",
"converter": {
"type": "json",
"filterExpression": "$",
"deviceNameJsonExpression": "${$.devEUI}",
"deviceTypeJsonExpression": "${$.applicationID}",
"timeout": 60000,
"timeseries": [{
"type": "double",
"key": "temperature",
"value": "${$.object.temperatureSensor.1}"
}, {
"type": "double",
"key": "humidity",
"value": "${$.object.humiditySensor.5}"
}, {
"type": "double",
"key": "latitude",
"value": "${$.object.gpsLocation.3.latitude}"
}, {
"type": "double",
"key": "longitude",
"value": "${$.object.gpsLocation.3.longitude}"
}, {
"type": "double",
"key": "pressure",
"value": "${$.object.barometer.2}"
}, {
"type": "double",
"key": "altitude",
"value": "${$.object.gpsLocation.3.altitude}"
}]
}
}],
"connectRequests": [],
"disconnectRequests": [],
"attributeRequests": [],
"attributeUpdates": [],
"serverSideRpc": []
}]
}
}]

Step 3. Enable Cayenne LPP payload codec in Lora Application Server Application configuration. Without this step you will need external convertor to decode base64 data from ChirpStack (prev. LoraServer).

After that data from LoraWAN network will be forwarded to ThingsBoard. Devices will register automatically.

Feel free to configure dashboard to display data from devices.

PS. Example payload from Lora App Server:

{
"applicationID": "1",
"applicationName": "Test-application",
"deviceName": "test-device",
"devEUI": "2b5d9eff1d3efa2y",
"rxInfo": [{
"gatewayID": "b827ebffff9edf58",
"name": "rpi-zero-dual-channel",
"rssi": -48,
"loRaSNR": 9,
"location": {
"latitude": 55.75395965576172,
"longitude": 37.620391845703125,
"altitude": 10
}
}],
"txInfo": {
"frequency": 868100000,
"dr": 5
},
"adr": false,
"fCnt": 1,
"fPort": 1,
"data": "AWcA4QJzKewDiAiB4wW9iwAAyAVoRw==",
"object": {
"temperatureSensor": {
"1": 22.5
},
"humiditySensor": {
"5": 35.5
},
"barometer": {
"2": 1073.2
},
"gpsLocation": {
"3": {
"latitude": 55.7539,
"longitude": 37.6203,
"altitude": 2
}
}
}
}