How RG-02 connect to the TTN platform to control the multi-node LoRaWAN module?

This article will explain how to use Ai-Thinker RG-02 gateway to connect to the TTN platform to realize data transmission and reception.

1.?????Preparation

Visit the TTN website and create/log in a personal account, select a cluster in the “Console” to start adding node devices and gateways.

图片无替代文字
图片无替代文字

2.????Create a gateway

图片无替代文字

Go to gateways → Add gateway → Fill in the gateway name ,GatewayEUI and the corresponding frequency band configuration information. Click“Create gateway” to completes the creation.

When creating a gateway, we need to fill in the matching gateway ID, which can be found on the RG-02 gateway WEB control page→Menu bar tabs LoRaWAN→LoRaWAN Semtech UDP→Obtained from the Gateway EUI option.

Configure the “NS mode” of the gateway as “Custom”, fill in the “server address” as the regional server where the TTN service is located, and use the default port of “1700”. For the basic configuration and operation instructions of the RG-02 gateway, please refer to the instructions in RG-02 SETUP.

图片无替代文字
图片无替代文字

After completing the above configuration and creation, you can view the current connection status of the gateway on the gateway details page.

图片无替代文字

?

3.????Create an application

Go to applications → Add application → Fill in the Application’s ID and name, click “Create application” to completes.

图片无替代文字
图片无替代文字

4.????Create a device

Enter the created application page and click “Add end device” to start adding node devices. You can fill in the preset configuration according to your needs or click “Generate” to automatically generate a new Key. Click “Register end device” to complete the creation.

图片无替代文字

Select “Manually” to custom create. (The default access method for creating devices is OTAA). In OTAA (Over-The-Air-Activation) connection mode, we need to save the three parameters of “Device EUI, APP EUI, and APP KEY”, which will be used for subsequent connection of the device. You can fill in the preset configuration according to your needs or click “Generate” a new key is automatically generated. Click “Register end device” to complete the creation.

图片无替代文字

If you need to create a device with ABP access mode, you need to configure it through the “advanced” option. In ABP (Activation By Personalization) connection mode, we need to save the three parameters of “Device address, AppSKey, NwkSKey”, which will be used for subsequent connection of the device. You can fill in the preset configuration as required or click “Generate” to automatically generate a new key. Click “Register end device” to complete the creation.

图片无替代文字

5.????Device Information

Select the frequency band to use according to your region and device, and make sure that the frequency band used by the device you are using matches the subband option used by the gateway.

The LoRaWAN version chooses to use “v1.0.2”, and the regional parameters use “RP001 Regional Parameters 1.0.2”->The connection method “OTAA/ABP” to be used by the device can be configured in the device creation link.

Compared with ABP, OTAA is more secure, but due to the “JoinAccept link”, the connection speed of OTAA will be slightly slower than that of ABP.

Use the serial port tool to connect the Ra-08H development board, the default connection configuration is “9600bps 8N1”. Send commands one by one, and fill in the corresponding command with the key information we obtained in the previous step.

6.????AT command flow in OTAA mode

Internet access & data upload?

AT+CJOINMODE=

AT+CRXP=1,1,869525000

AT+CDEVEUI=70B3D57ED0052256 AT+CAPPEUI=0000000000000000

AT+CAPPKEY=8D5EC8F6834BDE677A3D815E81A14981 AT+CFREQBANDMASK=0001

AT+CULDLMODE=2

AT+DTRX=0,2,6,445566 AT+DTRX=1,1,4,55550        

Data downlink


receive data: rssi = -54, snr = 14, datarate = 5
rx: port = 1, len = 2
0x88 0x88

OK+RECV:03,01,02,8888        


receive data: rssi = -54, snr = 14, datarate = 5 rx: port = 1, len 

0x88 0x88

?

OK+RECV:03,01,02,88882 =        


7.????AT command flow in ABP mode


AT+CJOINMODE=
AT+CRXP=1, 1, 869525000
AT+CDEVEUI=70B3D57ED0052257
AT+CDEVADDR=260B43F6
AT+CAPPSKEY=8BADC0C41832EFDD46EF5DABB6BC667E
AT+CNWKSKEY=30C8F755AF7EC4E26EB79FFEDE824E39
AT+CULDLMODE=2
AT+CCLASS=2
AT+CFREOBANDMASK=0001
AT+DTRX=0, 2, 6, 223344        

8. TTN log view

Live Data

图片无替代文字

After completing the execution of the above AT commands, if the device is normally connected to the gateway, we can see the connection log of the device and the upstream data information on the TTN management page.

图片无替代文字

Click the “Messaging option” to manually send data to the device.

Note: When the device uploads data, the latest data delivered by the gateway will be obtained.

Messaging data delivery

9. MQTT Client


receive data: rssi = -54, snr = 14, datarate = 5
rx: port = 1, len = 2
0x88 0x88        

Obtain TTN server data through MQTT CLIENT to achieve data acquisition/distribution. The connected MQTT SERVER URL and port and login user information can be obtained on the TTN page.

图片无替代文字

Uplink Topic


v3/{application id}@{tenant id}/devices/{device id}/up        

Downlink Topic



v3/{application id}@{tenant id}/devices/{device id}/down/push        



//eg:

v3/000000000000@ttn/devices/eui-xxxxxxxxxxxxxxx/down/push

{

  "downlinks": [
        
    {
            
       "f_port": 15,
            
       "frm_payload": "vu8=", 
       "priority": "NORMAL", 
       "confirmed": true                   
    }
                              
   ]
                              
  }?        

?Note: The payload of subscription data is base64 encoded format.

图片无替代文字

要查看或添加评论,请登录

Ai-Thinker的更多文章

社区洞察

其他会员也浏览了