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 contents of the box. (📷: Alasdair Allan)
Measuring the operating temperature of the Gateway with an laser thermometer. (📷: Alasdair Allan)

Getting the Software

Deploying to The Things Network

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

Adding an application.

Registering a Device

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

Writing the Software

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

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

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





Scientist, Author, Hacker, Maker, and Journalist.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

It’s time for something new — ELCASH has a new official website!

Etcd Performance Consideration

Write a Custom event handler using the WSO2 Identity Server Eventing Framework

StegaPwn CyberSpace Kenya Walthrough

Reduce Cost and Increase Productivity with Value Added IT Services from buzinessware — {link} -

An Awesome Tool Every Docker User Should Use

What is the Alter System in PostgreSQL ? | Interview Q& A

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.

More from Medium

So Easy MicroPython — Wifi Auto Connector, IoT

Virtual Machines on the Raspberry Pi!

Raspberry Pi 4: Don’t use /dev/ttyS0!

Build Private Cloud with OpenStack Kolla-ansible Step by Step Guide 1.0