Connect “Dragino LG01-P” gateway and a “Dragino Lora Shield+Arduino Uno” to The Things Network (TTN)

Marco Zecchini
4 min readSep 24, 2018

--

I am trying to design and develop a Smart Water Monitoring Systems using “LoRa” to send data collected by the sensors involved in the future prototype I will develop.

In this preliminary article, it is described how to manage the connections between the devices I am going to use and “The Things Network”, the very well-known platform that allows linking LoRa application to Internet. Moreover, some sensitive data taken by an LDR sensor are sent to a TTN registered application. So for this tutorial the following devices are taken into account:

  • Dragino LG01-P that is used as gateway for the TTN network
  • Dragino Lora Shield extension board
  • Arduino Uno
  • LDR sensor
  • 100K resistor
  • Breadboard and wires

Configuration of the Dragino LG01-P gateway

First we need to connect Dragino to internet. This can be achieved in two ways either using an Ethernet cable or configuring the device as WiFi Client.

To accomplish both the connections we firstly need to link the Dragino gateway to our PC through another Ethernet cable using the LAN port. This, as the port name suggests, creates a LAN among the two items and gives us the opportunity to access the configuration page just typing in the browser this IP: “10.130.1.1”.

Here we can proceed in two different ways both navigating to “Network -> Internet Access”:

  • Ethernet procedure, selecting in the “Access Internet Via” the option “WAN port” and linking the WAN port to the internet router.
  • Wifi procedure, selecting in “Access Internet Via” the option “WiFi Client”, filling “SSID”, “Password” and “Encryption” with the proper information.

Now we can create a gateway into the TTN platform. Note that a LoRa gateway is used to receive packets from LoRa devices and forward them to the TTN networks or in the inverse process. Note that Dragino LG01 supports only the single channel gateway to connect to TTN server.

User needs to create a gateway in the TTN Console, making sure to use “legacy packet forward method” and as unique gateway ID I suggest using the MAC address of the Dragino, which is indicated at the bottom of the device, plus a suffix; the ID is a unique 8 Byte Hex. For example: as below, the mac for the device is a8:40:41:17:c6:92, a user then can add ffff suffix and get the gateway ID: a8404117c692ffff.

Gateway ID
Gateway registration

Just some settings are missing now: we need to browse in LG01 Sensor → LoRaWAN page to input the correct Lora Radio settings used to receive data from the LoRa nodes.

Setting example for EU868 LoRaWAN Radio

Finally, we need to configure the LoRaWAN Server both going to LG01 Sensor → LoRaWAN following the information below …

TTN Europe Router Configuration

… and then enabling to use LoRaWAN server.

LoRaWAN enabled!

Checking now in the TTN Console is possible to see connected out gateway and ready to receive messages! For any problem or any troubleshooting issue I refer you to the Dragino Wiki page.

Configuration and development of the TTN Node

The device node, composed by an Arduino Uno + Dragino LoRa Shield, once it is correctly registered in TTN collects the LDR data and send them through LoRa.

To register the device into TTN, we have to browse the console, click on Application and, if it is necessary, on Add Application. Once we can access the application page, scrolling down a bit we must select the buttons indicated below.

In the next page opened we need to fill the “Device ID” field with a unique name for our device and ask for random generation of both “Device EUI” and “AppKey”. After that click on “Register”.

We are almost done with the registration; we just missing browse “Settings” and enable “ABP” as “Activation Mode” asking for random generation of the “App Session Key” and the “Network Session Key”.

This is how the Console shows the node information at the end of the registration

The last step of this tutorial provides the instructions of how getting the LDR value and the code that we need to upload in Arduino.

Arduino LDR Connections

To interact with the LoRa Radio I have used an Arduino library by matthijskooijman, linked at this page, that can be installed following these instructions. The code below runs the task that we want to achieve, just remember to edit the variables “NWSKEY”, “APPSKEY” and “DEVADDR” with the Network Session Key, the Application Session Key and the Device Address provided by the TTN console.

--

--