pdf-icon

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.

Preparation

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.

Accessing TTN website and console Selecting a cluster

Creating an Application

Go to applications -> Add application -> Fill in the Application ID and application name as desired, then click Create application to finish creating.

Creating an application Application details Application created

Creating a Device

Enter the created application page and click Add end device to start adding a node device. Choose Manually to custom create.

Adding a device

Device Information

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.

In the device creation step, you can configure the connection method to be used OTAA/ABP:
OTAA is more secure compared to ABP, but due to the JoinAccept step in OTAA, the network connection speed is slightly slower than ABP.

OTAA

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.

OTAA device registration

ABP

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.

ABP device registration ABP device details

Programming the Device

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.

  • For OTAA connection, you will need Device EUI, APP EUI, APP KEY.
  • For ABP connection, you will need Device address, AppSKey, NwkSKey.

UIFlow

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.

Other LoRaWAN module Blocks in UIFlow are supported and essentially identical to this program; you can refer to this example for modification/running tests.
  • OTAA connection example program

OTAA connection in UIFlow

Arduino

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
);

Viewing TTN Logs

Live Data

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.

TTN Live Data

Clicking Messaging allows manual data transmission to the device. Note: The latest data from the gateway is obtained only when the device uploads data.

Messaging Data Transmission

TTN Messaging

MQTT Client

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.

MQTT Client information

v3/{application id}@{tenant id}/devices/{device id}/up
v3/{application id}@{tenant id}/devices/{device id}/down/push
Note: The payload of subscribed data is in base64 encoding format.

MQTT Topics

More Information

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 .

On This Page