Transmit Data to TTN With LoRawan

by Lan_Makerfabs in Circuits > Arduino

5278 Views, 5 Favorites, 0 Comments

Transmit Data to TTN With LoRawan

LoRaWANnode009.jpg

In this project, I will introduce you to how to transmit the data to TTN by LoRaWAN.

In some of my previous projects, I was using some LoRa modules to achieve some ideas. A few people who interested asked whether the project supports the LoRaWAN or the module can transmit the data to TTN (the things network) by LoRaWAN. Unfortunately, my answer is NO.

So, I wanted to build a project to transmit the data to TTN by LoRaWAN.

Overview

LoRaWANnode003.jpg

LoRaWAN is a low-power, wide-area networking protocol built on top of the LoRa technique. It wirelessly connects devices to the internet and manages communication between end-node devices and network gateways. The LoRaWAN gateway or router is an important component for LoRaWAN. It bridges LoRa wireless network to the Ethernet network via WiFi or cable.

TTN, The Things Network is a global community of more than 110000 active members from over 100 countries around the world for LoRaWAN.

In this chapter, I wanted to connect the DHT11 module to an Arduino board as the LoRaWAN node and transmit the reading to TTN via LoRaWAN.

Arduino Board

Maduino-Zero-LoRaWAN-2-1000x750.jpg
Maduino Zero LoRaWAN Node Schematic.png

For supporting the LoRaWAN, I purchased a LoRaWAN module—Ra-07H. I design one Maduino board that features the LoRaWAN module and SAMD21G18A microcontroller, which to be the LoRaWAN node supporting the Arduino. The Maduino LoRaWAN board provides many expansion GPIOs for connecting the sensor, that meets my need to connect the DHT11 module.

The Ra-07H module already has loaded the firmware that supports the AT command. According to the Maduino LoRaWAN board schematic, the Ra-07h connects with MCU through the serial that you can send the AT command to LoRaWAN module by serial.

Next, I was going to start transmitting the data by using this board.

LoRaWAN Gateway

As the picture in the Overview shown, the Maduino LoRaWAN Board does not connect the TTN directly as the node. Maduino LoRaWAN board transmits the data to LoRaWAN gateway by LoRaWAN, then the gateway transmits the data to TTN through the internet. So that the LoRaWAN board cannot transmit the data to TTN without the LoRaWAN gateway.

The LoRaWAN Router I used is the Dragino one. For connecting to TTN, I have to config the gateway to be a TTN gateway follow the user manual.

Setting an Application on TTN

LoRaWANnode004.jpg

For transmitting the data to TTN(The Things Network), It is necessary to learn the usage of TTN in advance, such as how to set an application, etc. After setting your application of TTN, there are three parameters to be important: Device EUI, APP Key, APP EUI.

  1. Enter the TTN website: https://console.thethingsnetwork.org/, and log in the account.
  2. Go to the console, select a cluster to start adding devices. (I choose the EU)
  3. Select Application on the page and add a new application.
  4. Fill in the application ID and other information, then create it.
  5. Add an End device, select the manually to choose the active mode to OTAA and LoRaWAN version, then follow the reminders to type in the parameters.
  6. On the device page, it is necessary to set the payload formatters for decode the payload LoRaWAN node transmitted. Choose the Uplink and select the Javascript. Type in the following code and save.
function Decoder(b, port) { 
  var var1 = b[0];
  var var2 = (b[1] << 8) | b[2];

  return {
    field1: var1,
    field2: var2/10
  }
}

The TTN application setting is finished.

Connecting

LoRaWANnode005.jpg

Connected the DHT11 module to the Maduino LoRaWAN board.

Coding

Lorawan module can connect to LoRaWAN in two ways:

Over-the-air Activation (OTAA): A device has to establish a network key and an application session key to connect with the network. Activation by Personalization (ABP): A device is hardcoded with keys needed to communicate with the network, making for a less secure but easier connection.

OTAA join mode is recommended to use for confidentiality. In the OTAA join mode, the LoRaWAN module has to configure the three parameters mentioned above. It does not need to set the LoRa frequency that it will connect the gateway one automatically (the LoRaWAN module also can work with this frequency).

Next will show the AT commands used:

AT+CDEVEUI=**********           set the device EUI parameter
AT+CAPPEUI=**********           set the APP EUI parameter
AT+CAPPKEY=**********			set the APP KEY parameter
AT+CJOINMODE=0 				set the join mode to OTAA
AT+CJOIN=1,0,10,1 				config the OTAA mode, first “1” enable the OTAA, “0” turn off the automatic of joining, “10” is the cycle time of joining. Second “1” is mean only one time to join. 
AT+DTRX=1,2,5,*******				“5” is the string length, “*******” is the payload.

The code is available on Github. Note to modify the parameters(Device EUI, APP Key, APP EUI) to yours.

Load the code to the Maduino LoRaWAN board.

Result

LoRaWANnode006.jpg

As the picture, the measurement had been transmitted to the TTN.

The original payload is 3C0119, and after payload formatter decoding, the data is 60 and 28.1, which mean the temperature is 28.1 C and humidity is 60%.