Interact with chirpstack server data
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.
The device information location is shown in the figure
// TOPIC uploaded by the device server
// display everything for the given APPLICATION_ID
// display only the uplink payloads for the given APPLICATION_ID
// Application server sends TOPIC
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
//Subscribe to the data upload TOPIC of a single device
//Subscribe to all devices under the current app
/* 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
The information received by the application server is shown in the figure
Application server sends information
//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)
//The terminal device reads data from the receive buffer and clears the buffer
The information received by the device is shown in the figure:
MQTT wildcards can only be used when subscribing, not when sending
ASCII to string
base64 encryption and decryption
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.
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:
Broker Port: 1883 (non-encrypted)
Client ID: just give one
User Name: Application ID, which is customized when registering the application, here is ff08
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:
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:
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.
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.
The plaintext corresponding to "MTIzNDU2Nzg5" is "123456789".
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.