A LoRaWAN “The Things Network” Gateway for Windows IoT Core
|Software apps and online services:|
This tutorial describes how to build, install and run a single-channel packet-forwarding LoRaWAN gateway running on a Raspberry Pi with a Dragino LoRa extension board, forwarding received radio packets to The Things Networkbackend. The gateway is implemented in C# (having no external dependencies) and runs on the Windows IoT Core platform.
Please note that the radio expansion boards used in this tutorial are single-channel only, which means that you will not be able to create a full-fledged gateway. It does not fulfill the complete standard and are not LoRaWAN compliant.
This gateway will be suitable for testing purposes only.
The LoRa Alliance describes LoRaWAN like this:
LoRaWAN™ is a Low Power Wide Area Network (LPWAN) specification intended for wireless battery operated Things in a regional, national or global network. LoRaWAN targets key requirements of Internet of Things such as secure bi-directional communication, mobility and localization services. The LoRaWAN specification provides seamless interoperability among smart Things without the need of complex local installations and gives back the freedom to the user, developer, businesses enabling the roll out of Internet of Things.
On top of that, The Things Network describes themselves like this:
We are a global community of 15235 [2017-05-07] people over 84 countries building a global Internet of Things data network. We use a long range and low power radio frequency protocol called LoRaWAN and for short range Bluetooth 4.2. The technology allows for things to talk to the internet without 3G or WiFi. So no WiFi codes and no mobile subscriptions.
So what is a Packet-Forwarding LoRaWAN Gateway?
In short; The Things Network is built up by people placing Gateways virtually all over the world that picks up LoRaWAN radio packets and forwards them to the backend of The Things Network. From there developers can access and process the data sent from their nodes in applications (living in the cloud).
A full-fledged gateway can also transmit messages from the backend (i.e. from the cloud applications) over the air back to the nodes. This functionality is missing in a packet-forwarding gateway.
But it’s a good start to play with the technique, anyway. And cheap.
The C# code is developed and tested on Raspberry Pi 3 (but version 2 would work just fine) with one of the following LoRa expansion boards:
The easiest expansion board to use is the Dragino LoRa/GPS HAT together with a Raspberry Pi, since it’s just to plug it on top (see the top photo).
If you decide to use one of the Dragino Arduino Shields you will need to connect the wires manually. A few of the wires can be attached to any of the general purpose IO pins of the Raspberry Pi, but others must be placed as in my descriptions. The schematics at the end of this article shows how the LoRa/GPS HAT would be attached if it would be attached using wires (except the serial port, which is not attached in my schematics). If you use my suggestion you can use my code as-is.
Next you will need to get my code, either clone or download it from my GitHub repository.
Now you open up the
Dragino.Lora.Demo.Gateway.sln solution file from my GitHub repository in Visual Studio.
In the top bar of Visual Studio, choose Arm as the solution platform and Remote Machine as target.
Open up the
MainPage.xaml.cs source code file and locate the four
YOUR EDITING IS REQUIRED HERE! -comments.
Here’s what you need to consider in those places:
#1. Configuring the radio chip
The first comment points out where you configure the LoRa radio chip by specifying the
LoraWanGatewaySettings -object instance.
The default is
Europe868 , but depending on where you live (and your radio chip hardware) you might need to change this.
Either use one of the predefined ones, or create a custom one. Take a look at how the predefined ones are created, if you need to create a custom!
#2. Configuring the connection to the LoRa expansion board
The second edit-comment in the MainPage code file is found in the
GetTransceiverPinSettings() method. It’s here you tell how your transceiver expansion board is wired to your Raspberry Pi. If you are using the LoRa/GPS HAT — or using an Arduino Shield with the wiring according to my schematics below — you can leave the code as is.
But if you used a custom wiring you will need to uncomment the last lines and specify the pin numbers yourself.
#3. Using a GPS
UseGpsManager() method. Depending on which expansion board you have, a GPS module might be present. The default code assumes that you have one, and returns
true . If you don’t have a GPS module, change this to
#4. Specifying the Gateway EUI
The last part of the code you will need to configure is the EUI of your gateway and is found in the
GetGatewayEui() -method. The EUI is a globally unique ID for your gateway. Unfortunately there is no unique ID provided by the LoRa module itself, so, for instance the MAC address of the Raspberry Pi could be used instead.
Using the MAC address
If you want to use the MAC address it’s slightly more complicated, because there isn’t (yet) an API giving you this information in Windows IoT Core. There is a however workaround, and that is to call the embedded REST API (the same that you can visit in a web browser to configure your device).
The URI that gives the MAC address information is found at
But you must provide the user name and password to get access to this API; i.e. the credentials you used during the installation of Windows IoT Core on the device. The default in the code is
[email protected] .
Using a hard coded EUI
You can also specify any EUI you want by removing the two top lines of this method and uncomment the last one which simply returnes a fixed value at
new GatewayEui("0123456789ABCDEF") . Obviously you should change the
0123...EF to your own unique hexadecimal value.
The Things Network
The next step is to go to the console and click the register gateway link. Now register your gateway using the following setup:
As Protocol, use packet forwarder since this gateway implementation is not a full-blown gateway connector.
As Gateway EUI you enter the EUI used by your application (see above). If you decided to use the MAC address you might need to start the application once to see the EUI written in the debug console of Visual Studio (in the output window). This is written by the line that says
WriteLog("The gateway EUI: " + gatewayEui);
Then you should give your gateway a name in the Description field, and choose the correct Frequency Plan depending on where you live and which radio module you are using.