ChirpStack LoRaWAN Integration
ChirpStack is an open source LoRaWAN network server stack. This tutorial explains how to receive LoRaWAN sensor data via ChirpStack using the MQTT Agent. The tutorial is based on the Dragino LHT65 LoRaWAN sensor device as an example.
Install and start ChirpStack
- Make a copy of the ChirpStack Docker repository with the following commands:
git clone https://github.com/brocaar/chirpstack-docker.git
cd chirpstack-docker
- Start ChirpStack
docker-compose up
- Login to the ChirpStack UI (http://localhost:8080/admin/admin)
Create the ChirpStack LoRaWAN Gateway
- Navigate to the Service-profilespage and click the+ Createbutton.
- Create a service profile with the following settings:
- Add gateway meta-data: enabled
- Enable network geolocation: enabled
- Minimum allowed data-rate: 0
- Maximum allowed data-rate: 5(Europe),4(US)
 
- Add gateway meta-data: 
- Navigate to the Gatewayspage and click+ Createbutton.
- Create a gateway with the following settings:
- Gateway ID: 8 byte hexadecimal number (e.g. a841452101b04161, see gateway device manual for how to retrieve the gateway ID)
- Network-server: docker-network-server
- Service-profile: service profile you created earlier
 
Create the ChirpStack LoRaWAN Device
- Navigate to the Applicationspage and click the+ Createbutton.
- Create an application with the following setting:
- Service-profile: service profile you created earlier
 
- Navigate to the Device-profilespage and click the+ Createbutton.
- Create a device profile with the following settings:
- General:
- LoRaWAN MAC version: see device manual (select 1.0.3in case of Dragino LHT65)
- LoRaWAN Regional Parameters revision: see device manual (select Ain case of Dragino LHT65)
- Max EIRP: 14(Europe)
- Uplink interval (seconds): see device configuration (select 1200in case of Dragino LHT65)
 
- LoRaWAN MAC version: see device manual (select 
- JOIN (OTAA/ABP):
- Device supports OTAA: enabled
 
- Device supports OTAA: 
- CODEC:
- Custom JavaScript decoder function: add a function that decodes the base64 encoded binary data (in case of the Dragino LHT65 go to the Dragino LHT65 support page in order to download a ChirpStack data decoder).
 
 
- General:
- Navigate to the Applicationspage and select the application you created earlier
- On the Devicestab click the+ Createbutton.
- Create a device with the following settings:
- General:
- DeviceEUI: 8 byte hexadecimal number (see LoRa device manual for how to retrieve this identifier from the device).
- Device-profile: device profile you created earlier
 
 
- General:
- Navigate to the KEYS (OTAA)tab and configure the new device with the following setting:- Application key: 16 byte hexadecimal number (see device manual for how to retrieve the application key from the device).
 
Create the OpenRemote MQTT agent
- Login to the OpenRemote manager UI (https://localhost/admin/secret)
- Navigate to the Assetspage, click+in the asset tree on the left.
- In the Add assetdialog do the following:- Select the MQTT Agentasset type in the list
- Name: ChirpStack MQTT Agent
- Confirm with ADD
 
- Select the 
- Click Modifyand configure the following asset attributes:- Host: IP address of the ChirpStack server (e.g. 192.168.170.83)
- Port: 1883
- Confirm with SAVE
 
Create the OpenRemote LoRaWAN device asset
- 
Navigate to the Assetspage, click+in the asset tree on the left.
- 
In the Add assetdialog do the following:- Select the Thing Assettype
- Name: Dragino LHT65
- Confirm with ADD
 
- Select the 
- 
Click Modify
- 
Click ADD ATTRIBUTEand do the following in theAdd attributedialog:- Type: Custom attribute
- Name: Temperature
- Value type: Number
- Confirm with ADD
 
- Type: 
- 
Expand the Temperatureattribute and clickADD CONFIGURATION ITEMS
- 
In the Add configuration itemsdialog do the following:- Select Agent linkin the list
- Confirm with ADD
 
- Select 
- 
Expand the Agent linkconfiguration item and configure theAgent ID:- Agent ID: Chirpstack MQTT Agent
 
- Agent ID: 
- 
Click ADD PARAMETERin order to add the MQTT topic configuration.
- 
In the Add parameterdialog do the following:- Select Subscription Topic
- Confirm with ADD
 
- Select 
- 
Edit the Subscription Topic.The ChirpStack MQTT topic for sensor values has the following format: application/{application id}/device/{deviceEUI}/event/up
 application id: see Applications list in the Chirpstack UI
 deviceEUI: 8 byte hexadecimal LoRaWAN device identifierExample for the Subscription Topicvalue:application/1/device/a841452101b04161/event/up
- 
Click ADD PARAMETERin order to add a json path configuration.
- 
In the Add parameterdialog do the following:
- Select Value Filters
- Confirm with ADD
- Expand the new Value Filtersparameter and clickADD ITEM
- In the Add itemdialog do the following:
- Select JSON Path
- Confirm with ADD
- Expand the new JSON Pathitem and do the following:
- Path: $.object.TempC_DS(Note: this is an example for the Dragino LHT65 data decoder)
- Return First: enabled
The following json structure shows an example of the Dragino LHT65 MQTT topic value:
{
  "applicationID":"1",
  "applicationName":"dragino-lht65-application",
  "deviceName":"dragino-lht65",
  "deviceProfileName":"lht65-profile",
  "deviceProfileID":"c3eb48d6-eddc-4038-bee9-1d5855d98d90",
  "devEUI":"a841452101b04161",
  "rxInfo":[
      {
        "gatewayID":"3499452178b04155",
        "uplinkID":"a1da5994-04c9-4bb7-ad2d-088c8668d2d1",
        "name":"dragino-lg308",
        "rssi":-55,
        "loRaSNR":9.5,
        "location": {
          "latitude":8.232323023,
          "longitude":7.8383283838,
          "altitude":664}
      }
  ],
  "txInfo": {
    "frequency":868100000,
    "dr":5
  },
  "adr":true,
  "fCnt":2064,
  "fPort":2,
  "data":"y+AG5wFZAQawf/8=",
  "object": {
    "BatV":3.04,
    "Ext_sensor":"Temperature Sensor",
    "Hum_SHT":"34.5",
    "TempC_DS":"17.12",
    "TempC_SHT":"17.67"
  }
}
- Click SAVE