Home >Product dynamics>Product dynamics
Tutorial: How to connect with LoRaWAN server for data sending and receiving

Interact with chirpstack server data

Prepare:

Use MQTTX software to subscribe to the target server. Here is the chirpstack server built by myself. The IP is 192.168.0.84. The user name and password are both admin, which can be written or not.

Subscribe TOPIC through the application server to accept the information published by the device server.

 step 1

The device information location is shown in the figure

step 2

 

Grammar:

// TOPIC uploaded by the device server

// display everything for the given APPLICATION_ID

application/APPLICATION_ID/#

// display only the uplink payloads for the given APPLICATION_ID

application/APPLICATION_ID/device/+/event/up

 

// Application server sends TOPIC

application/APPLICATION_ID/device/DEV_EUI/command/down

 

Note: '#' and '+' are wildcards in the MQTT protocol

Single-level wildcard (Single-level wildcard): represented by the symbol "+". When a level in a topic uses the "+" wildcard, it matches any name of a level. For example, "home/+" can match topics such as "home/bedroom", "home/livingroom", etc., but not more than one level of topics such as "home/bedroom/temperature".

Multi-level wildcard (Multi-level wildcard): represented by the symbol "#". When a level in a theme uses the "#" wildcard, it can match any name at multiple levels. "#" must be the last level of a topic, which matches the current level as well as all deeper topics. For example, "home/#" can match "home/bedroom", "home/livingroom", and "home/bedroom/temperature" at any level of theme.

Device Push Information

//Receive TOPIC:

//Subscribe to the data upload TOPIC of a single device

application/ded77c98-1249-44d1-9a14-c4b312f71d77/device/a1b117f518a3ba80/event/up

//Subscribe to all devices under the current app

application/ded77c98-1249-44d1-9a14-c4b312f71d77/#

/* AT command for terminal node to upload data

1: Need to confirm the frame // 0 does not need to confirm

2: The maximum number of retransmissions is 2 times

10: The number of bytes in the current package

xx:data */

AT+DTRX=1,2,10,3435363738

The information received by the application server is shown in the figure

 step 3

Application server sends information

//Send TOPIC:

application/ded77c98-1249-44d1-9a14-c4b312f71d77/device/a1b117f518a3ba80/command/down

//Send data format

{

"devEui": "a1b117f518a3ba80", #Device ID

"confirmed": true, #Whether confirmation is required

"fPort": 10, #Target application layer port

"data": "cnVub29i" #data, note: need to use base64 encoding format eg:cnVub29i == 72756E6F6F62(runoob)

}

 step 4

//The terminal device reads data from the receive buffer and clears the buffer

AT+DRX?

The information received by the device is shown in the figure:

 step 5

Notice:

MQTT wildcards can only be used when subscribing, not when sending

Tools website:

ASCII to string

https://www.asciim.cn/m/tools/convert_ascii_to_string.html

base64 encryption and decryption

https://c.runoob.com/front-end/693/

 

Interact with TTN server data

 

In the previous article, we mainly explained how to register gateways, create applications, create devices, etc. on thethingsnetwork.org. thethingsnetwork.org (hereinafter referred to as TTN) is just a network server (network server) and will not save application data. Therefore, in the actual project An application server is also required. thethingsnetwork.org provides a variety of ways for the application platform to obtain data and manage devices.

 

Mainly divided into 3 categories:

APIs: It is divided into data API and application management API. The data API mainly uses MQTT to receive and send data, and the application management API mainly uses HTTP to manage registered devices.

SDKs: Various languages such as Go, Java, Node.js are provided.

Integrations: ThingSpeak, AWS IOT, etc.

In most cases, you only need to pay attention to reporting and sending data, so this article mainly explains how to use MQTT to obtain data and send data, the official description https://www.thethingsnetwork.org/docs/applications/mqtt/api.html

 

The MQTT.fx client is used here to demonstrate that other high-level language MQTT clients may be used in practical applications.

 

Connect

 step 6

 

Mainly the four parameters in the above block diagram, among which:

Broker Address: <Region>.thethings.network, where <Region> is the selected region.

This parameter is also the Handler we chose when we registered the application, which is the address on the right in the figure below:

 step 7

step 8

 

Broker Port: 1883 (non-encrypted)

Client ID: just give one

User Name: Application ID, which is customized when registering the application, here is ff08

 step 9

Password: application access key, in base64 format, this is generated by the system, of course you can also add it yourself, here is the one generated by the system:

 step 10

Subscribe (Subscribe) node uplink data

 

TTN provides a topic Topic: <AppID>/devices/<DevID>/up, where <AppID> and <DevID> are both defined during registration, and you can see it when you enter the corresponding device, as follows:

 

 step 11

step 12

You can see the node ID, reported port number, counter, frequency point, timestamp, etc., where the payload_raw field is the data we uploaded, which is displayed in base64 format.

Publish (Publish) downlink data
TTN provides a topic Topic: <AppID>/devices/<DevID>/down, where <AppID> and <DevID> are both defined during registration, and can be seen when entering the corresponding device.
step 14

The data is in json format, the above three fields are required, and the payload_raw field is the data we want to send, which is in base64 format.

step 15

The plaintext corresponding to "MTIzNDU2Nzg5" is "123456789".


China Lorawan gateway Manufacturer and Factory

Modem & DTU sale . As a China Lorawan gateway Manufacturer and Lorawan node modules Factory, CDEBYTE focuses on providing wholesale Lorawan gateway and  Lorawan node modules. Supports standard LoRaWAN network protocols, and access to standard LoRaWAN servers such as TTN, Tencent, and open-source chip stack. The instructions are simply configured to access the standard LoraWan In the network, it's a great choice for current IoT applications.