GPS Tracking with LoRa

April 27, 2019 - Reading time: 6 minutes

I recently bought a Dragino LoRa IoT development kit development kit from the IoT store here in Perth. It's a pretty cheap way to experiment with LoRa, and comes with 2 Arduino Uno boards, one LoRa shield, and one LoRa + GPS shield. In addition, it comes with a LoRa 'gateway' device which allows you to bridge a LoRa network to an IP network (via WiFi or Ethernet). The device cannot be considered a true LoRa gateway since it only communicates over a single frequency, whereas the LoRa RF pysical layer uses spread spectrum modulation. Still, its good enough for some quick prototyping.

LoRa gateway setup and config

The Dragino gateway can be hooked up to the Things Network following the guide here. Below are the settings on my gateway - the key is the radio settings, and specifically the Tx and Rx frequency, as these will be needed when configuring a LoRa client to communicate with the gateway.

Image description

Within the Things Network, I add the gateway as a LoRaWAN gateway using the eui of the device. The gateway is configured to use the legacy packet forwarder.

Image description

Once the gateway is hooked up and you can see it on the Things Network console successfully, you'll need to create an application within the Things Network console to represent a data flow from your LoRa client, through the gateway and into the IP network. This is very simple to do within the console and once complete, you can add a device to your application, to represent a LoRa client that will transmit data. When creating the device, you'll need to select a device EUI for your device - the Dragino shields do not seem to have EUIs so for testing, generate your own. The device will have a Network Session Key and an App session key generated as shown below

Image description

Once the gateway, application, and device are configured in the Things Network, you can write some code on the Arduino board with the LoRa shield attached, to communicate with the gateway - ultimately the aim is to use the LoRa + GPS shield to periodically take GPS readings, and transmit these to the gateway, which will forward them to the Things Network.

Device code

Getting the LoRa shield to communicate with the gateway in the Australian LoRa frequency band (915-928 MHz) turned out to be a bit tricky until I found Thomas Laurenson and his superb post on how to do just that here combined with his fork of the Arduino LMIC library. Thanks Thomas!

Wiring up the hardware Since the Arduino UNO board has a software serial, we need to wire up the shield as shown below, and described here

Image description

In the code for the device board, available here I make use of the Cayenne LPP library from TTN to make it super simple to send packets of GPS data.

Once the board is succesfully transmitting messages and you can see them being received in the Things Network console, you can set up an integration within the console to do something with the received messages. I simply post the received message (which is decoded from LoRa / Cayenne within the Things Network without me needing to do anything), to an API gateway backed Lambda in AWS which simply persists the message in a Dynamo DB table. The entire backend infrastructure to support this is defined in this serverless script.

The type of integration set up in TTN is an HTTP integration which allows you to specify the API gateway endpoint and api key. Each time a message is received over the air by your gateway, it is sent to TTN, decoded from Cayenne, and then POSTed to the specified HTTP endpoint.

Image description

Visualising the data

Once I had data flowing into Dynamo, I wrote a simple ReactJS page using Pigeon maps to visualise the co-ordinates of the points captured by the GPS receiver, and sent via LoRa and TTN into AWS.

Image description

All code for the Arduino device, the front and back end is available in GitHub