How to Setup a local LoRa Gateway for The things network
Tags: iot, esp, lora
Published: 2023-03-12 08:53:53

---
title: How to Setup a local LoRa Gateway for The things network
published: true
date: 2022-03-13 08:00:00 cest
tags: IoT, ESP, LoRa
canonical_url: https://blog.bajonczak.com/how-to-setup-a-local-lora-gateway-for-the-things-network/
---

 ![How to Setup a local LoRa Gateway for The things network](https://images.unsplash.com/photo-1603695576504-b2b22b530965?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDZ8fElvdHxlbnwwfHx8fDE2NzA3NDI3NTY&ixlib=rb-4.0.3&q=80&w=2000)

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

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-1.png)

#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](https://www.thethingsnetwork.org/) (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](https://www.amazon.de/AZDelivery-NodeMCU-ESP32-Display-433Mhz/dp/B08243JHMW/ref=asc_df_B08243JHMW?tag=bingshoppin0b-21&linkCode=df0&hvadid=80745497106067&hvnetw=o&hvqmt=e&hvbmt=be&hvdev=c&hvlocint=&hvlocphy=&hvtargid=pla-4584345027534276&psc=1), this contains a oled display and also a LoRa chip that can act as receiver in my case.

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-2.png)

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

 ![How to Setup a local LoRa Gateway for The things network](https://opengraph.githubassets.com/5a51d619ac0d5903adcb5c474bfd5e3f45c065f911ddc308deb6ce4b27d60445/things4u/ESP-1ch-Gateway)
](https://github.com/things4u/ESP-1ch-Gateway)

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.

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-3.png)

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

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-4.png)

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

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-5.png)

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

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-6.png)

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.

![How to Setup a local LoRa Gateway for The things network](https://blog.bajonczak.com/content/images/2022/12/image-7.png)

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.