Run your LoRaWAN gateway with your own The Things Stack network server on a Raspberry Pi and balena

mpous

Marc Pous

Posted on August 27, 2021

Run your LoRaWAN gateway with your own The Things Stack network server on a Raspberry Pi and balena

Running this project you can have all the LoRaWAN stack (Basics Station gateway + The Things Stack network server) running together on a single Raspberry Pi, LoRa concentrator and balena. Using containers on balena means that it can run alongside with other services such as the balena LoRaWAN BasicsTM Station gateway and others.

Alt Text

What is LoRa and LoRaWAN

I love the concept of the Low-Power Wide Area Networks (LPWAN). LPWAN enable to set up tiny sensors running with batteries far away from the base stations and still send data during a lot of time.

LoRa is a radio modulation meant for Long Range communication using very little power to send data.

LoRaWAN is a Media Acces Layer (MAC) protocol. A software layer that defines how devices use LoRa to transmit and receive messages on a network.

Alt Text

LoRaWAN (LoRa Wide Area Network) is an example of LPWAN. Using LoRa (Long Range) radio-frequencies, you can send tiny packages of data over long distances (even miles away depending on the topology) with simple battery-powered devices. The radio packets are captured by gateways which relay over the Internet the LoRa packages to network servers.
The Things Stack is an example of a LoRaWAN network server. The Things Stack (previously The Things Network) is being run on the The Things Industries clusters that are distributed worldwide.

Alt Text

Why is this Running on a Raspberry Pi instead of a cloud?

If you want to manage your own data without sharing it with any cloud provider, the data collected can’t leave your country, or other similar requirements, then the solution is to deploy The Things Stack LoRaWAN Network Server using balena on a Raspberry Pi.

If you are a professional that needs to build your ad-hoc LoRaWAN private network for tests or others, this is a great and unexpensive solution. And if you are a community or company who need a tiny private LoRaWAN network server, this could be just enough.

Some people says that a Raspberry Pi is to small for this type of job, but it has been running for weeks with good performance with tiny amount of LoRa nodes. Needs to be tested on a bigger environment. Feel free to bring your feedback here.

Hardware and Software required

Alt Text

  • Raspberry Pi 3 or 4 (or similar Compute Module carrier boards).
  • SD card
  • Power supply
  • LoRa concentrator (SX1301 or SX1302) (e.g. RAK 2245, RAK 2287 among others)

  • balenaCloud account

  • balena Etcher to flash the SD card.

Deploy the Basics Station gateway with The Things Stack network server

To deploy the Basics(TM) Station gateway service along TTS local network server on your Raspberry Pi, click the Deploy with balena here or go to the Github repo to click the Deploy with balena button to automatically deploy the application on balenaCloud.

Alt Text

Clicking the deploy button will create a fleet with all the necessary code to deploy your The Things Stack plus basicstation service.

It’s time to connect your LoRa concentrator compatible with your Raspberry Pi or balena Fin (SX1301, or SX1302 and SX1303 such as RAK2245 or RAK 2287), to run the LoRaWAN gateway running alongside with The Things Stack network server.

Remember to add or modify the variable MODEL depending on the LoRa concentrator model you have (SX1301, SX1302 or SX1303). By default is set to SX1301.

You should see something similar on balenaCloud as below:

Alt Text

You will notice that the services will reboot a few times, this is normal behaviour to set up all the services properly.

Register the gateway at your private The Things Stack

Copy your local IP address and paste it into the browser with https. Accept the self-signed certificate that the device has generated automatically for your local IP address. Alternatevaly feel free to use the public URL generated by balenaCloud.

Alt Text

Login using the credentials User ID admin and the password changeme. Feel free to change your Password after you log in.

Alt Text

Click Register a gateway and then Add new Gateway. Copy the EUI that the basicstation service introduces as a TAG of on the balenaCloud dashboard. Paste it as the EUI of the gateway when registering.

Alt Text

Now the gateway is registered and it's time to generate an API Key. Go to Add API Key, then select Link as a Gateway to a Gateway Server for traffic exchange, i.e. write uplink and red downlink. Click the button Create API key. Remember to copy the key.

Alt Text

Paste the key on the balenaCloud Device Variables of the device on balenaCloud as TC_KEY.

The gateway registered will be online on your private The Things Stack network server and able to receive data from your LoRa nodes.

This project involves a lot of services running together. If there is any issue not reported here, feel free to report it at the balena forums.

And remember that this project is open source, feel free to contribute to improve it.

💖 💪 🙅 🚩
mpous
Marc Pous

Posted on August 27, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related