This tutorial will show the setup of a LoRaWAN network, including configurations on gateway/end nodes and data workflow with scripts.
1. Write the RAK7243 firmware image in gateway, see how to write here.
2. Config the gateway with the build-in ChirpStack, see Quickstart.
The default mode for nodes joining LoRaWAN is OTAA. If nodes want to join with ABP mode, configuration of node should be modified as following:
- Define the marco
CHIRPBOX_LORAWAN_ABPin the STM32Cube project:
- Device profile set with
disable frame-counter validation.
- Device address, network session and application session key should consist with the firmware.
- Login to gateway and open chirpstack-network-server configuration:
pi@rak-gateway:~ $ sudo nano ../../etc/chirpstack-network-server/chirpstack-network-server.toml
disable_mac_commands=true, save and reboot the gateway.
2. End node
The example project is based on I-CUBE-LRWAN, where modifications in this project are within the define-marco
3. Data forwarding
3.1 MQTT to MySQL Database
The MQTT integration can publish data from gateway bridge and application server in JSON format. In this tutorial, we store those retrieved data in MYSQL server.
1. MQTT settings
- Login to gateway and open chirpstack-gateway-bridge configuration:
pi@rak-gateway:~ $ sudo nano ../../etc/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml
marshaler="json", save and reboot the gateway.
Use the MQTT Explorer to check if we can receive data through MQTT
- Login with the gateway host address and MQTT port
- See live events from gateway
2. MYSQL settings
- Install MYSQL and MYSQL GUI tool Navicat on Windows.
- After installation, start MYSQL service in command line with your MYSQL name, for example
net start mysqltest
- Create a new user
1111, and grant privileges in MYSQL command line client:
CREATE USER 'lorawan'@'%' IDENTIFIED BY '1111';
- Connect to MYSQL service with
3.1.2 Python examples
1. MQTT live events
- This example subscribes and publishs the topic as shown in MQTT explorer, for example
- See topic name format here
2. Log MQTT data to MYSQL database
- This example subscribes the topic
application/2/#and saves data in the MYSQL database nased
- Table name is generated automatically according to the UTC time.
- We store the UTC time, device EUI, RX and TX information in the table, which can be seen through Navicat:
3.2 ChirpStack API
ChirpStack APIs are provided to achieve data integration. See how to setup with following steps:
3.2.1 JWT config
1. JWT secret
- Login to gateway and generate a JWT secret
pi@rak-gateway:~ $ openssl rand -base64 32
Get the result, for example:
- Open the chirpstack-application-server configuration:
pi@rak-gateway:~ $ sudo nano ../../etc/chirpstack-application-server/chirpstack-application-server.toml
Oto save the configuration.
2. JWT token
- Open jwt.io and input the decoded data with Header and Payload respectively:
your-256-bit-secretwith the JWT secret (do not tick the
secret base64 encoded)
- The JWT token is then shown in the left
- If you want to verify if the JWT token is valid, go to the ChirpStack API web interface (http://localhost:8080/api, localhost is the ip_address of the gateway):
- Input JWT token on web interface
Try it out!below the page
- If the
Response Codeis not
200, check above steps to make sure JWT secret and JWT token are correct.
3. Network Address Translator (NAT)
- To build NAT of the gateway for external network access, download Oray for Raspberry Pi and put it in
- Execute following commands in the
pi@rak-gateway:~ $ sudo -s
- Control phddns with following commands and make sure it is online
phddns start | status | stop |restart | reset |enable (Turn on self-starting)|disable(Turn off self-starting) |version
- Login to Oray with the SN code and password
- Follow these steps to create the domain name connected to the gateway built-in ChirpStack
- Then we can access the ChirpStack through the Internet with created address:
3.2.2 Python examples
1. Enqueue downlink packets to the specified device
- This example is based on Downlink to Device provided by ChirpStack
2. Enqueue downlink packets to group
- Update device profile to supply Class C (when using Class A, remember to untick the Class C support)
- Add a multicast group with following configurations:
- Add devices in this group:
- Copy the group ID for Python codes:
3.3 HTTP integration
HTTP integration with the Pipedream platform is fast to achieve data retrieving from ChirpStack.
1. Pipedream connection
- Sign in Pipedream and select
- Select and create a source with following (default) configs:
- Copy the HTTP endpoint:
- Create the HTTP integration on ChirpStack’s application and paste the endpoint address:
- Uplink LoRaWAN packets are shown as events in the inspector:
2. Pipedream SQL service
- Scroll down the source and tick
- Set a name of this workflow and deploy it:
- Turn on for listening new events, and then create a new action as
Send JSON to Pipedream SQL Service
- Input a
Table Nameand select path of
- Select SQL and run
select * from lorawan_chirpboxto query data (there is a 60-second delay of SQL for events):
3.3.2 Code examples
Pipedream provides APIs to retrieve events from source and SQL. Code examples are written in
cURL, which can be converted to
1. Live events
- Obtain Pipedream API key here
- Get summary events and refresh them with commands
- Note: packet payload are encoded as base64 strings, see online decode tool.
2. Database events