Contents:

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.

https://wiki.dragino.com/images/thumb/f/f4/ChirpStack_home_page.png/600px-ChirpStack_home_page.png

ChirpStack home page

2) Gateway model support

Semtech UDP : All Model
Basic Station : , , 
Note : the firmware needs >  if use the Bais station

2. Semtech UDP

2.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.

https://wiki.dragino.com/images/thumb/6/6b/Add_the_Network-servers.png/600px-Add_the_Network-servers.png

Add the Network-servers

2.2 Step 2. Create Gateway-profiles

https://wiki.dragino.com/images/thumb/a/a9/Create_Gateway-profiles.png/600px-Create_Gateway-profiles.png

Create Gateway-profiles

2.3 Step 3. Create Service-profiles

https://wiki.dragino.com/images/thumb/1/1f/Create_Service-profiles.png/600px-Create_Service-profiles.png

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.

2.4 Step 4. Add the gateway

The example gateway id is: a840411e96744150

Note : The Gateway EUI and server addresses must match the ChirpStack configuration.

https://wiki.dragino.com/images/thumb/c/c6/Add_the_gateway.png/600px-Add_the_gateway.png

Add the gateway

https://wiki.dragino.com/images/thumb/1/14/ChirpStack_Configure_the_gateway.png/600px-ChirpStack_Configure_the_gateway.png

Configure the gateway

2.5 Step 5. Checking gateway Status

https://wiki.dragino.com/images/thumb/2/2c/Gateway_Status_cao_1.png/600px-Gateway_Status_cao_1.png

gateway Status

https://wiki.dragino.com/images/thumb/1/11/Gateway_Status_cao_2.png/600px-Gateway_Status_cao_2.png

gateway Status

3. Semtech Basic Station

4. Downlink

4.1 Chirpstack Downlink Note

https://wiki.dragino.com/images/thumb/b/ba/ChirpStack_Down_5.png/600px-ChirpStack_Down_5.png

Convert the data to Base64

https://wiki.dragino.com/images/thumb/2/2c/ChirpStack_Down_6.png/600px-ChirpStack_Down_6.png

Check ChripStack downlink DataRate

https://wiki.dragino.com/images/thumb/d/dc/ChirpStack_Down_7.png/600px-ChirpStack_Down_7.png

Make sure the RX2DR is the same in the end node

4.2 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

https://wiki.dragino.com/images/thumb/0/06/ChirpStack_Down_1.png/600px-ChirpStack_Down_1.png

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"} 

https://wiki.dragino.com/images/thumb/c/c8/ChirpStack_Down_2.png/600px-ChirpStack_Down_2.png

MQTT Connect to ChirpStack

Note: Chirpstack use base64 to downlink, so need to convert the downlink payload from HEX to base64 https://base64.us/

https://wiki.dragino.com/images/thumb/f/f8/ChirpStack_Down_3.png/600px-ChirpStack_Down_3.png

Choose to Use Hex for Encode

If we want send downstream hex 030101 to end node, the BASE64 payload is AwEB

ChirpStack Down 4.png

Downlink payload encode javescript code: 可以在网站上运行以下Javsscript代码:

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.charCodeAtthumb_down - 55;
        }
        else if(sha1[n] >= 'a' && sha1[n] <= 'z')
        {
           ascv = sha1.charCodeAtthumb_down - 87;
        }
        else
        {
            ascv = sha1.charCodeAtthumb_down - 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.

4.3 Add the decode function in Chirpstack for the payload

User enters the payload code according to the steps.

Step2.png

Step3.png

Step6.png

Step5.png

5. 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 1.png

nbtrans is a field of ADR message, in unconfirm mode, it tells end node how many time it needs to transmit for every frame.

Nbtrans 2.png

Above behaviour will cause the platform shows below two cases of error:

Error of duplicate Frame Counter

Nbtrans 3.png

Duplicate transmission in short time

Nbtrans 4.png

5.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.

Chirpstacksolution-1.png

installation path:

Chirpstacksolution-2.png

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)

Chirpstacksolution-3.png

3)Modify the system variable Path and add C:\Go\bin\:

Chirpstacksolution-4.png

User variable setting file generation directory: D:\go:

Chirpstacksolution-5.png

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:

Chirpstacksolution-6.jpg

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.

Chirpstacksolution-7.png

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:

Chirpstacksolution-8.png

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:

Chirpstacksolution-9.png

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,

Chirpstacksolution-10.png

Finish.

6. Trouble Shooting

6.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.

Tags:
    
Copyright ©2010-2022 Dragino Technology Co., LTD. All rights reserved
Dragino Wiki v2.0