This tutorial will guide you on how to create applications and node devices in TTN (The Things Network), configure the M5Stack LoRaWAN module to connect to the TTN service, and achieve data transmission and reception. Note: This tutorial is only applicable to areas covered by the TTN gateway. Individuals in areas not covered will need to establish their own gateways for connection.
Access the TTN website and create/log into a personal account
, and select a cluster in the Console
to start adding node devices and gateways.
Go to applications
-> Add application
-> Fill in the Application ID
and application name as desired, then click Create application
to finish creating.
Enter the created application page and click Add end device
to start adding a node device. Choose Manually
to custom create.
Select the frequency band based on your location and device, ensuring that the frequency band used by your device matches the sub-band options used by the gateway. Choose LoRaWAN version v1.0.2
and regional parameters RP001 Regional Parameters 1.0.2
.
OTAA/ABP
: JoinAccept
step in OTAA, the network connection speed is slightly slower than ABP.For OTAA (Over-The-Air-Activation) connection mode
, save the Device EUI
, APP EUI
, APP KEY
parameters for later use in device connection. You can enter preset configurations or click Generate
to automatically generate new keys. Click Register end device
to complete creation.
For ABP (Activation By Personalization) connection mode
, save the Device address
, AppSKey
, NwkSKey
parameters for later use in device connection. You can enter preset configurations or click Generate
to automatically generate new keys. Click Register end device
to complete creation.
In the previous steps, we successfully created a device in TTN. Next, we need to program the device to connect it to the gateway. Please enter the connection parameters obtained in the previous step in the example programs below for different platforms, depending on the connection method.
Device EUI
, APP EUI
, APP KEY
.Device address
, AppSKey
, NwkSKey
.Below is an example using the UNIT LoRaWAN, fill in the connection parameters obtained in the previous steps into the configuration program, and ensure the frequency band
, Class Mode
, Rx2 frequency window
, etc., match your actual settings. Then, run the program for testing.
Click the links below to obtain the example programs and driver libraries for the corresponding devices. Refer to the configuration functions below to modify the program's contents, entering the connection parameters obtained in the previous step.
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 program editing/running operation, if the device is successfully connected to the gateway, we can see the device's connection logs and the uplink data information in the TTN management page.
Clicking Messaging
allows manual data transmission to the device. Note: The latest data from the gateway is obtained only when the device uploads data
.
Obtain TTN server data through the MQTT CLIENT for data retrieval/transmission. The MQTT SERVER URL, 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
base64
encoding 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 .