This tutorial will show you how to create applications and node devices in TTN, configure the M5Stack LoRaWAN module to connect to the TTN service, and realize data sending and receiving.
Note: This tutorial is only applicable to the TTN gateway coverage area
, individual users in the uncovered area need to build their own gateway to connect.
Visit the TTN website and create/login a personal account
, select a cluster in Console
to start adding node devices and gateways.
Go to applications
-> Add application
-> Customize Application ID
and application name, and click Create application
to complete the creation.
Enter the created application page and click Add end device
to start adding node devices, and select Manually
to customize the creation
Select the frequency band to use according to the region and device you are using, and ensure that the frequency band used by the device you are using matches the sub-band 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
.
You can configure the connection method OTAA/ABP
to be used by the device in the device creation process:
OTAA is more secure than ABP, but due to the presence of the JoinAccept
link, the speed of OTAA's network connection is relatively high. It will be slightly slower for ABP.
In OTAA(Over-The-Air-Activation) connection mode
, we need to save Device EUI
, APP EUI
, APP KEY
these three parameters 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.
In ABP(Activation By Personalization) connection mode
, we need to save Device address
, AppSKey
, NwkSKey
, these three parameters will be used for subsequent connection of the device, you can fill in the preset configuration according to your needs or click Generate
to automatically generate new key. Click Register end device
to complete the creation.
In the previous steps, we successfully created the device in TTN, next we need to program the device to connect to the gateway. Please pass in the connection parameters obtained in the previous step in order according to the device connection method in the case program corresponding to different platforms below.
Device EUI
, APP EUI
, APP KEY
.Device address
, AppSKey
, NwkSKey
.The following uses UNIT LoRaWAN as an example, fill in the connection parameters obtained in the previous step into the configuration program one by one, and make sure that the band
, Class Mode
, receive window Rx2 freq
and other configurations match the actual ones, and then Run the program to test.
The block support of other LoRaWAN modules in UIFlow is basically the same as this program. You can refer to this case for modification/running test.
Click the link below to obtain the case program and driver library for selecting the corresponding device, and refer to the configuration function below to modify the content of the program, and pass in the connection parameters obtained in the previous step in turn.
LoRaWAN.configOTTA(
"70B3D57ED004E460", // Device EUI
"0000000000000000", // APP EUI
"6BEBAED3A9FA853ED6885D6E50497736", // APP KEY
"2" // Upload Download Mode
);
LoRaWAN.configABP(
"260B6E5C",//Device ADDR
"63F68EE76CC3034D142B6F1695B70D43",//APP SKEY
"3CB3FA729FD7191061F963F5E8167837",//Nwk SKEY
"2"//Upload Download Mode
);
After completing the above program editing/running operations, if the device is connected to the gateway normally, on the TTN management page, we can see the device's connection log and uplink data information.
Click the Messaging
option to support manually sending data to the device. Note: When the device uploads data, it will get the latest data sent by the gateway
.
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.
v3/{application id}@{tenant id}/devices/{device id}/up
v3/{application id}@{tenant id}/devices/{device id}/down/push
Note: The payload of subscription data is in base64
encoded format.
For more detailed tutorials on TTN integration interfaces (MQTT, Webhooks, Storage Integration, AWS IoT, Azure IoT Hub, LoRa Cloud), please refer to TTN Integration Development Documentation