Photo by Jorge Ramirez / Unsplash

How to Setup a local LoRa Gateway for The things network

IOT Dec 11, 2022

I work @ home with several sensors, and all of them and I mean really all of them require a wifi connection. Okay some of them use the 433 Mhz band to communicate but that is 4 of ... hundreds ;). So in my case, I must create a separate network to avoid a negative impact on my home network. But my router now has come to the limitation of the wifi connection amount. I need more sensors but without wifi, here comes LoRa and LoRaWan in.

What is Lora?

LoRa is the abbreviation of "Long Range Wide Area" and as such is a low-power wireless network protocol. The LoRaWAN specification is defined by the LoRa Alliance and is freely available.

It is a protocol that is adjusted to the IoT World's requirements. So it is less power consuming and it archives ...yeah long range (about 9 KM and more) communications. This will be used basically for an end to end communication where all devices (Sender and Gateway) nearby reachable. Like a star network like this

What is now LoRaWan?

Let's consider that you're running some devices out in the wild. So you can now try to send data with a cellphone and so on but when you need several sensors then it will cost you very much. So instead you can use a local LoRa (star) network and the gateway send it to a centralized hub like The Things Network (TTN).

A word about The Things network

The Things Network provides a set of open tools and a global, open network to build your next IoT application at low cost, featuring maximum security and ready to scale.

So this is a large network with several gateways that private people running at their homes or elsewhere and they are ready to receive data from your device. The best thing about this is, that you can integrate it within an existing hyper scaler message broker like azure ServiceBus or IoT hub.

So this article will introduce you, to how your will host a single channel LoRa Gateway that will get connected to TTN.

What do we need?

So first of all we need a device that can send and handle LoRa messages. I use for this a Heltec Device, this contains a oled display and also a LoRa chip that can act as receiver in my case.

Next we need some code, for this I found a nice handy repo that will give me the possibility to running the Heltec Device as gateway

GitHub - things4u/ESP-1ch-Gateway: Version 6 of the single channel gateway
Version 6 of the single channel gateway. Contribute to things4u/ESP-1ch-Gateway development by creating an account on GitHub.

You will see that there are many many files in this repo, but to keep this very simple you will only need to change only one file "configNode.h". In this you will Setup the Wifi-Connection to your network.

So you will see that there is the possibility to add more than one network. Each key value Pair represents the SSID and the associated passwort to the network. So Adding one single network will look like this

Now you can upload your firmware to your heltec device, and it is ready to run.

The Interface

Once you have connected the device to a power source, you will see an IP Address on the Oled Display.  With this Ip you can connect to a rich web portal in which we can see many statistics about our gateway

On the same page, you will see information about the local IP, the router gateway and the important part the GW ID.

Register a Device on TTN

Before we get ready to run a gateway for The things network we must regstier the device on their portal

Our LoRa gateway can be easily registered on the network through the console section, where the user simply has to add a new LoRaWAN Gateway by clicking on the “Register gateway” label.

Then, you have to choose a name and the right parameters. You will also need one parameter, which is the Gateway ID and it is uniquely related to the LoRa modem onboard so that each node has a unique ID. You can find it inside the LoRaWAN Web server interface under the voice “Gateway ID“, and it’s a 16 characters string. Put it into the right TTN field and complete the registration process, then your GW is ready to provide LoRaWAN connectivity to your applications.

Easy eh?

Closing thoughts

You see there is nothing special to run a gateway, but pay attention, this is a very cheap solution with on single channel. So it will works well for two or three nodes, otherwise you can get into trouble with collisions and will loose data. Also every node must operate on the same channel that your device actually is operating at. To many uplinks may cause a reboot. So lets be serious it is for a home project not for the open world, because it is not helpful for the network. But you can use it in your own projects as simple and foremost CHEAP gateway.

So I must switch to a more powerful device like a raspberry pi, for me is this gateway a nice handy element to collect telemetry data from my beehives (weights and so on). When I create the raspberry Pi device, I will take you with me on my journey.