Notes for ChirpStack
Table of Contents:
- 1. Introduction
- 2. Node usage introduction
- 3. Semtech UDP for ChirpStack v3
- 4. Semtech UDP for ChirpStack v4
- 5. Gateway Registration for Basics Station
- 6. How the gateway connects to Chirpstack v3 via gateway-bridge
- 7. How the gateway connects to Chirpstack v4 via gateway-bridge
- 8. Downlink
- 9. Chirpstack Multicast Configuration
- 10. Multiply Uplink in ChirpStack
- 11. How to store/get all data traffic for a specific sensor, including raw payload, and uplink/ downlink history.
- 12. How to use Chirpstack API to batch register Sensor Node/Gateway in Chistapstack Server
- 13. Example: Use Local Server ChirpStack and Node-Red in LPS8v2
- 14. Trouble Shooting
1. Introduction
The ChirpStack open-source LoRaWAN Network Server stack provides open-source components for LoRaWAN networks And the Chirpstack supports the users in building a private LoRaWAN Server. For more info please refer to this link
The dragino gateway can connect the ChirpStack server via Semtech UDP or Semtech Basic Station.
Prerequisite:
1) Have a Chirstack Server.
ChirpStack home page
2) Gateway model support
Semtech UDP : All Model
Basic Station : LIG16, LG308, DLOS8 LPS8
Note : the firmware needs >lgw--build-v5.4.1640315898 if use the Bais station
2. Node usage introduction
2.1 Register Node
Step 1: Add application
Step 2:Fill name
Step3 :Add device profile
Step4 :Configure your device profile
Does node support class-c
Add node's decoder
Step5 :add device
3. Semtech UDP for ChirpStack v3
3.1 Step 1. Add the Network-servers
The network-Servers address varies depending on the ChirpStack server setup environment
Windows --> Network-server server * : localhost:8000
Linux --> Network-server server * : chirpstack-network-server:8000
If the user cannot add network-Servers, re-check the ChirpStack code or the server building process.
Add the Network-servers
3.2 Step 2. Create Gateway-profiles
Create Gateway-profiles
3.3 Step 3. Create Service-profiles
Create Service-profiles
In Step 3. Create Service-profiles, the above parameters can be set. If necessary, you can set them by yourself. This is only an example.
Note : Before add the gateway, the user needs to complete the preceding three steps.
If the user has completed the preceding steps, proceed to the next step.
3.4 Step 4. Add the gateway
The example gateway id is: a840411e96744150
Note : The Gateway EUI and server addresses must match the ChirpStack configuration.
Add the gateway
Configure the gateway
3.5 Step 5. Checking gateway Status
gateway Status
gateway Status
4. Semtech UDP for ChirpStack v4
4.1 Step 1. Add the gateway
4.2 Step 2. Checking gateway Status
5. Gateway Registration for Basics Station
5.1 Introduction
The Semtech Basic Station backend implements the LNS protocol. It exposes a WebSocket handler to which Basic Station powered gateways can connect.
ChirpStack Open-Source LoRaWAN® Network Server needs to set up a configuration that can use Semtech BasicStation.
Below list the support products and Requirements:
- LoRaWAN Gateway model: LIG16, LG308, DLOS8 ,LPS8
- Firmware version since :lgw--build-v5.4.1651822913
How to set up chirpStack Basic Station
Users can check out the ChirpStack Basic Station link and forum
What do you need to prepare
A gateway that can access the internet normally
5.2 Add Gateway
5.3 Access the gateway GUI
Access the gateway GUI interface of LoRaWAN-->LoRaWAN -- Basic Station
User need to Choose the ChirpStack/Senet -- Basic Station , input Server URI and Upload the TLS Certificate
Service Provider --> Choose the ChirpStack/Senet -- Basic Station
LNS URI --> Enter the LNS URI address, For example : wss://xxxx.chirpstack.com:443 or ws://xxxx.chirpstack.com:3001
LNS TLS trust --> Upload the TLS Certificate
5.4 Start Station
When the user has finished the configuration, Please click Sace&Apply to start station to connect ChirpStack.
5.5 Successful Connection
If user completes the above steps, which will see live date in the ChirpStack.
5.6 Trouble Shooting
User can check the station log in the logread/system log page.
and recode the station log in the system/Recode log page.
6. How the gateway connects to Chirpstack v3 via gateway-bridge
Below list the support products and Requirements:
- LoRaWAN Gateway model: LIG16, LG308, DLOS8 ,LPS8,LPS8N,LG308N,DLOS8N
- Firmware version since: Chirpstack-Bridge-V3.14.6
What do you need to prepare
A gateway that can access the internet normally
The following example does not have configuration certificates:
6.1 Configure Packet Forwarder
In the Dragino gateway web interface, you need to configure the Packet Forwarder so that it forwards its data to the port. localhost:1700 or 127.0.0.1:1700
- In the LoRaWAN menu, click on LoRaWAN -- Semtech UDP
- Make sure the following settings are set:
- Service Provider: --Custom/Private LoRaWAN--
- LoRaWAN Server Address: localhost or 127.0.0.1
- Server port for upstream: 1700
- Server port for downstream: 1700
Click Save & Apply.
6.2 Configuring gateway frequency
Note: Gateway frequencies must match
6.3 Generate and modify the gateway-bridge configuration file
1)Generate the gateway-bridge configuration file
By default, the configuration file is not up-to-date,so the user needs to rebuild the gateway-bridge configuration file.
Users need to access the command line of the gateway through SSH,Then type the following command:
2)modify the gateway-bridge configuration file
The user needs to modify the server address in line 252 in the configuration file
6.4 Debug
After the above configuration is completed, the user can enter the command to debug the gateway-bridge connection
If the gateway-bridge connection is normal, the debug log displays "connected to mqtt broker".
If the debug log shows "connection error", check that the server port or server is correct
More information can be found on the ChirpStack websiteor Forum
6.5 (Re)start and stop gateway-bridge
Use the following commands to (re)start and stop the ChirpStack Gateway Bridge Service:
7. How the gateway connects to Chirpstack v4 via gateway-bridge
Below list the support products and Requirements:
- LoRaWAN Gateway model: LIG16, LG308, DLOS8 ,LPS8,LPS8N,LG308N,DLOS8N
- Firmware version since: Chirpstack-Bridge-V4
What do you need to prepare
A gateway that can access the internet normally
7.1 Configure Packet Forwarder
In the Dragino gateway web interface, you need to configure the Packet Forwarder so that it forwards its data to the port. localhost:1700 or 127.0.0.1:1700
- In the LoRaWAN menu, click on LoRaWAN -- Semtech UDP
- Make sure the following settings are set:
- Service Provider: --Custom/Private LoRaWAN--
- LoRaWAN Server Address: localhost or 127.0.0.1
- Server port for upstream: 1700
- Server port for downstream: 1700
Click Save & Apply.
7.2 Configuring gateway frequency
Note: Gateway frequencies must match
7.3 Modify the gateway-bridge configuration file
Run the gateway command line command to modify the gateway-bridge configuration file:
Configure the server address to which the gateway needs to be connected,"tcp://chirpstack_address:1883"
After the modification, run the following command: /etc/init.d/chirpstack-gateway-bridge restart
7.4 (Re)start and stop gateway-bridge
Use the following commands to (re)start and stop the ChirpStack Gateway Bridge Service:
7.5 Successful Connection
8. Downlink
8.1 Chirpstack Downlink Note
Select HEX format for downlink
Note: The end node user manual provides HEX format of the downlink commands, so users can directly select HEX format downlink.
Check ChripStack downlink DataRate
Make sure the RX2DR is the same in the end node
8.3 Loraserver Downlink Note
User can use MQTT to send downlink payload to ChirpStack to perform downstream to LoRaWAN End
Below is examples:
Connect to your server via MQTT:
MQTT Client ID: Any
Protocol:mqtt/tcp Server IP:loraserver_ip:1883
User name: User name Password: password
MQTT Connect to ChirpStack
After connect
Subscribe : Format:application/ID/device/ Device EUI/rx
Example: application/7/device/00aedb3da649cb23/rx
Publish:
Format: Top: application/ID/device/ Device EUI/tx
Payload: {"confirmed":true or false,"fPort":XX,"data":"xxxx"}
Example: Top: application/7/device/00aedb3da649cb23/tx
Payload: {"confirmed":true,"fPort":2,"data":"AwEB"}
MQTT Connect to ChirpStack
Downlink payload encode javescript code.
We can run the following Javsscript code on the site:
function sha1_to_base64(sha1)
{
var digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64_rep = "";
var cnt = 0;
var bit_arr = 0;
var bit_num = 0;
for(var n = 0; n < sha1.length; ++n)
{
if(sha1[n] >= 'A' && sha1[n] <= 'Z')
{
ascv = sha1.charCodeAt( n ) - 55;
}
else if(sha1[n] >= 'a' && sha1[n] <= 'z')
{
ascv = sha1.charCodeAt( n ) - 87;
}
else
{
ascv = sha1.charCodeAt( n ) - 48;
}
bit_arr = (bit_arr << 4) | ascv;
bit_num += 4;
if(bit_num >= 6)
{
bit_num -= 6;
base64_rep += digits[bit_arr >>> bit_num];
bit_arr &= ~(-1 << bit_num);
}
}
if(bit_num > 0)
{
bit_arr <<= 6 - bit_num;
base64_rep += digits[bit_arr];
}
var padding = base64_rep.length % 4;
if(padding > 0)
{
for(var n = 0; n < 4 - padding; ++n)
{
base64_rep += "=";
}
}
return base64_rep;
}
console.log(sha1_to_base64("data"));
data is downlink payload required by end node.
e.g console.log(sha1_to_base64("030101"));
result: AwEB
AwEB is the 0x030101's base 64 Encode.
e.g console.log(sha1_to_base64("030000"));
result: AwAA
AwAA is 0x030000's base 64 Encode.
8.4 Add the decode function in Chirpstack for the payload
User enters the payload code according to the steps.
Add the node device decoder you are using. The decoder for each node device is different. The decoder is found in this link: decoder for dragino end node
9. Chirpstack Multicast Configuration
9.1 Introduction
ChirpStack has support for creating multicast-groups to which devices can be assigned. When enqueueing a downlink payload for a multicast-group, ChirpStack will analyze which gateways must be used for broadcasting to cover the complete multicast-group. This means that potentially, a single multicast downlink payload will be emitted multiple times.
Multicast can be used for the following device-classes:
- Class-B
- Class-C
9.2 Example to configure chirpstack Multicast
This section illustrates how to configure ChirpStack Multicast. Below is the network structure, we use our LPS8v2 as the LoRaWAN gateway and two SN50v3-LB as the LoRaWAN end-node here.
This example assumes that the user already has the prerequisites:
- SN50v3-LB Software Location: .Users need to flash them with the firmware support Multicast.
- SN50v3-LB Configure: Enable CLASS C and DISFCNTCHECK(The downlink fcnt is not compared with the fcnt of the node).
AT command: AT+CLASS=C
AT+DISFCNTCHECK=1
For details on how to configure the SN50v3-LB, please refer to the link: Configure SN50v3-LB
- Chirpstack Configuration: LPS8v2 gateway and SN50v3-LB register on ChirpStack server already
Register LPS8v2 gateway to Chirpstack. See section :https://wiki.dragino.com/xwiki/bin/view/Main/Notes%20for%20ChirpStack/#H4.A0SemtechUDPforChirpStackv4
Register SN50v3-LB to Chirpstack. See section :https://wiki.dragino.com/xwiki/bin/view/Main/Notes%20for%20ChirpStack/#H2.A0Nodeusageintroduction
Step 1. Create the multicast group
Create the multicast group on the corresponding Application-->multicast groups-->Add multicast-group interface, For example, multicast_test01_au915
Enter the Multicast address,Multicast network session key,Multicast application session key.
Use the default LoRaWAN settings, as below:
- EU868: 869525000hz, DR0
- US915: 923300000hz, DR8
- CN470: 505300000hz, DR0
- AU915: 923300000hz, DR8
- AS923: 923200000hz, DR2
- KR920: 921900000hz, DR0
- IN865: 866550000hz, DR2
- RU864: 869100000hz, DR0
Group type: Class-C
Class-C scheduling type : Delay
Step 2. Add gateways and devices to the multicast group
Select a gateway on the "Gateways" screen, click "selected gateways", and click "Add to multicast-group" to add the gateway to the corresponding multicast group, for example, multicast_test01_au915.
On the Application->Devices interface, select two SN50v3-LB nodes registered with multicast support, and then click "Selected devices". and click "Add to multicast-group" to add the node to the corresponding multicast group
Access the multicast group to check whether two SN50V3-LBs and gateways are added successfully
Step 3. Use the API for multicast Downlink
To use API Downlink, user first need to generate an API key
For example:https://www.chirpstack.io/docs/chirpstack/api/index.html
Users can access the Linux console of the gateway via SSH, and then use the curl command to multicast Downlink
The format is as follows:
In the command,eyJ........._2v4UYPV0w is the API key, which can be obtained from the Chirpstack server and the data format is base64,
Result
Connecting to the SN50v3-LB using the serial USB-TTL port can check that two SN50v3-LBs are receiving Downlink at the same time
10. Multiply Uplink in ChirpStack
nbtrans field is the value to determine the re-transmission time for unconfirmed uplink data.
ChirpStack will auto adjust nbtrans according to uplink rssi. link to source
nbtrans is a field of ADR message, in unconfirm mode, it tells end node how many time it needs to transmit for every frame.
Above behaviour will cause the platform shows below two cases of error:
Error of duplicate Frame Counter
Duplicate transmission in short time
10.1 Solution
This example uses the Windows version as a template, other versions can refer to this. Similiar reference: https://confluence.alitecs.de/plugins/servlet/mobile?contentId=79790102#content/view/79790102
1. Install the GO compilation environment: Download the corresponding version of the Go compiler at https://go.dev/dl/ and install it.
installation path:
2. Environment variable settings:
1) Open Computer -> Properties -> Advanced System Settings -> Environment Variables and add a "new" system variable:
2) Set the variable name GOROOT and the variable value C:\Go\ (installation directory)
3) Modify the system variable Path and add C:\Go\bin\:
User variable setting file generation directory: D:\go:
3. Modify the ADR configuration file according to your own needs, adr.setting.go is an example of the ADR configuration file.
The name of the plugin: Example ADR plugin:
Set Nbtrans: Nbtrans=1 (Nbtrans is the number of retransmissions, if it is 1, no retransmission, it is recommended to be 1). To enable it, you need to uncomment.
4. Compile the ADR configuration file and generate the exe file.
1) Create a folder named adr-setting
2) Open the adr-setting folder
3) Put adr.setting.go in this folder.
4) Open the computer cmd and run the following commands in sequencecd adr-setting
go mod init adr-setting
go get github.com/brocaar/chirpstack-network-server/v3/adr
go get github.com/hashicorp/go-plugin
go get adr-setting
go build
5) Finally generate this file:
5. Add the plugin and run the plugin.
The exe file generated in the previous step is placed in the same root directory as chirpstack-network-server.toml, and the ADR plugin is added to the toml file. The location of the addition is as follows:
For example: adr_plugins=[“adr-setting”]
Adding a single plugin format is adr_plugins=["filename"]
Adding multiple plugins The format is adr_plugins=["file name 1", "file name 2",...]
Finally, re-run chirpstack-network-server.exe, and then select the plugin you just compiled in Device-profiles,
Finish.
11. How to store/get all data traffic for a specific sensor, including raw payload, and uplink/ downlink history.
All data is published to the MQTT topics. if you want to store/get the data, you would have to create an MQTT handler and store the data yourself.
This example will be shown how to store/get all the data in two ways:
1). Chirpstack --> Node-red
Use MQTT in Nore-red to subscribe to topics published by the chirpstack-application and then continuously write to a file
Each message is continuously logged to a specified file
2). MQTT Sub
If you don't want to store the information via node-red, you can get the output via the subscribe command.
If connecting from the same machine, you can use the following command to receive data:
Different host
12. How to use Chirpstack API to batch register Sensor Node/Gateway in Chistapstack Server
The following example is based on the built-in ChirpStack server for LPS8V2
12.1 Generate API Tokens
Access the built-in chirpstack , click "API Key" and "Add API Key".
Save the generated API Tokens
12.2 Template file
Click on "Template File Download", the user will download a register.csv template file,
Before registering in batches, the user needs to add an Application and Device profile, If you have already added them, you do not need to add them again,
Open the corresponding Application and Device profile and copy their IDs
12.3 Batch Register
Check whether the batch registration is successful
13. Example: Use Local Server ChirpStack and Node-Red in LPS8v2
LPS8v2 includes a local ChirpStack Server and Node-Red. This example shows how to configure LHT65N to use with the local Node-Red server. This example assumes users already have:
- LHT65N register on LPS8v2 Built-In ChirpStack server already
- The user is able to see the data on the built-in ChirpStack server device page.
Below are the steps to plot the sensor data on LPS8v2 Node-Red.
13.1 Link Node-Red to Local ChirpStack
Users can download the Node-Red decoder from this link and import it into the Node-Red platform:
For more information on importing Input Flow, check out this link: Import Input Flow for Dragino Sensors
After importing the Input Flow is complete, the user needs to edit the MQTT in the node
1. Change the Topic
Topic modifies it to the following format:
application/Application ID/device/End device ID/event/up
Reference link: Node-RED integration
2. Enter the MQTT configuration information
3. Finally, click "Update" and Deploy
"Connected" indicates that the Link Node-red to Local Chirpstack is normal.
13.2 Check result.
Users can check logs by adding debug.
Browser access: Node-Red-Server-Address:1880/ui
14. Trouble Shooting
14.1 MIC Mismatch or MIC Failed
When the device is registered or the device is working normally, the problem of MIC mismatch and MIC failed occurs.
Under normal circumstances, users need to change the APPKEY to solve this problem.
14.2 The node is very close to the gateway, but the signal is poor
If you are using US915 or AU915, you found the frequency points of different subband ranges in your uplink
Like that:Both 905.1Mhz and 902.3Mhz appear on uplink
But they belong to Subband1 and Subband2 of US915 respectively
Cause: The server and the gateway use different frequency bands (the server uses Subband1, and the gateway uses Subband2)
In server side, it shows the frequency is 905.1Mhz, which is sub-band2. But the RSSI is very low, Because this is not a signal in 905.1Mhz, it is on 902.3Mhz, the signal is too strong and appear a noise in 905.1Mhz.
How to check the frequency band used by the server:
You can view the information sent by the server: ch_mask in Unconfirmdedatadown
According to lorawan's protocol, your first ch_mask is 7 for ChMaskCntl = 7 then 125 kHz channels are disabled. Simultaneously the channels 64 to 71 are set according to the ChMask bit mask.
In the second message, the channel 0~7 is true, which means that your server is using subband2.
Note: lorawan's protocol link——LoRaWAN® Regional Parameters v1.0.3revA (lora-alliance.org)
14.3 ChirpStackv4 node device displays "UPLINK_F_CNT_RETRANSMISSION"
This is because the node's packets are retransmitted, and the Fcnt of these packets is the same.
The user can Disable frame-counter validation on the chirpstack node and this warning message will not appear in the logs.
The packet is retransmitted because the node device has enabled the acknowledgment uplink packet mode and the node cannot receive the ACK acknowledgment packet delivered by the gateway.
The possible reasons are:
1. The signal of the node device and the gateway is not good
2. Too many node devices affect the downlink of the gateway
- Disable frame-counter validation
- Result
14.4 How to get the log information of the node?
1. Get information about a single node.
- Download this file in the node's live data interface.
- The LoRaWAN frames download gateway receives real-time data from the current node.
2. Get information about the entire Gateway.
- Click to select the online gateway of the current node.
- Download this file on the LoRaWAN frames interface.
After the data collection is completed, you can send this file directly to our technical support personnel for analysis.
You can also use the packet analysis tool developed by our company to check it yourself. Please refer to the following link to use this tool.