Hands-on with the New PiSupply LoRa Gateway and The Things Network

Pre-release version of the PiSupply IoT LoRa Gateway HAT with a Raspberry Pi 3 Model B+. (📷: Alasdair Allan)

Assembling the Gateway

The gateway comes as a kit, but don’t worry, there isn’t any soldering required. Just insert the provided 40-pin male header block into the headers on the HAT and then—after screwing the brass spacers into your Raspberry Pi board—push the HAT firmly down on to your board.

The contents of the box. (📷: Alasdair Allan)
Measuring the operating temperature of the Gateway with an laser thermometer. (📷: Alasdair Allan)

Getting the Software

Pi Supply offer three options to install the software needed onto the gateway. The first, and much easiest method, and the one I used myself, is simply to download the prebuilt SD Card image and then do some quick configuration.

Deploying to The Things Network

To configure our gateway hardware to talk to The Things Network we’ll first need to configure it in the The Things Network Console.

The Things Network Console.
Adding our gateway.
The gateway is connected! (📷: Alasdair Allan)
Our connected gateway.
The gateway live on The Things Network.

Creating an Application

While any LoRa device in range of your new gateway will have its packets received, and sent up stream to The Things Network, the data packets will be dropped on the ground unless they have somewhere to go. In other words The Things Network needs to know where to route the packets your gateway is receiving.

Adding an application.

Registering a Device

This can be done from the Application’s page in the console.

Registering a device to an Application.
from network import LoRa
import ubinascii
lora = LoRa(mode=LoRa.LORAWAN)

Writing the Software

All we need now is to deploy some software onto our device and push the data from it up to our Gateway and The Things Network.

Our device, we’ll need the Application EUI and Application Key.
from network import LoRa
import socket
import time
import ubinascii
import pycom
from pysense import Pysense
from LIS2HH12 import LIS2HH12
from SI7006A20 import SI7006A20
from LTR329ALS01 import LTR329ALS01
from MPL3115A2 import MPL3115A2,ALTITUDE,PRESSURE
off = 0x000000
red = 0x220000
green = 0x002200
blue = 0x000022
pycom.heartbeat(False)py = Pysense()
mp = MPL3115A2(py,mode=ALTITUDE) # Returns height in meters.
mpp = MPL3115A2(py,mode=PRESSURE) # Returns pressure in pascals
si = SI7006A20(py)
lt = LTR329ALS01(py)
li = LIS2HH12(py)
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)
app_eui = ubinascii.unhexlify(<APP_EUI>)
app_key = ubinascii.unhexlify(<APP_KEY>)
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)
while not lora.has_joined():
print('Not joined yet...')
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
i = 0
while True:
i = i + 1
temperature = str(si.temperature())
pressure = str(mpp.pressure())
humidity = str(si.humidity())
string = "{\"count\": %i,\"weather\":{\"t\": %s,\"p\": %s,\"h\": %s}}" % (i,temperature,pressure,humidity)
A Pycom FiPy board (left) next to the Pi Supply Gateway (right). (📷: Alasdair Allan)
The logged data packets showing in our Application.

Adding a Decoder

Our device is dispatching a JSON object up to The Things Network via our gateway. However what you’ll see in the console is a series of hex values, the raw bytes, we’ve send up to the cloud. Don’t worry, it’s really rather trivial to add a decoder to our application to allow us to translate this back into our JSON object so we can see what is being sent back in the console.

function Decoder(bytes, port) {
return JSON.parse(String.fromCharCode.apply(null, bytes));
function Decoder(bytes, port) {
return { MyPacket: String.fromCharCode.apply(null, bytes) };
The data tab of the console, showing the decoded packet.

Adding an Integration

If we want to save our data we need to go ahead and add an integration.

The Things Network offers a number of different integrations.
How to: Storage integration. (📹: The Things Network)
How to: HTTP Integration. (📹: The Things Network)


Final production hardware should be going out to Kickstarter backers in February or March next year, but if you didn’t back the gateway on Kickstarter pre-orders are now open on the Pi Supply site. The gateway cost £129.98 plus shipping, with both EU (868 MHz) and US (915 MHz) versions of the HAT available, and pre-orders made now should start shipping just as soon as the Kickstarter backers have their orders fulfilled.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alasdair Allan

Alasdair Allan

Scientist, Author, Hacker, Maker, and Journalist.