Deploy an IoT Gateway and Node on TTN.
Last update: 2023.01.12
Some time ago, I built a LoRaWan gateway that I deployed on The Things Network (TTN). The gateway has a Raspberry Pi 3+ and a IoT Gateway HAT from Pi Supply. The board utilises the RAKWireless RAK833 LoRa gateway concentrator module.
It also has a Pi PoE Switch HAT and a PiJuice HAT, also from Pi Supply. In addition to the LoRa antenna, I put a Small GNSS Antenna (GPS) that I purchased at the Antennas & RF Electronics Store. All is assembled in the Nebra IP67 Enclosure.
I have deployed the software using balenaCloud. This conveniently allows to remotely manage and update the gateway through the balenaCloud application.
The Gateway is then deployed on TTN.
I am also using a Raspberry Pi IoT LoRa pHAT together with a Raspberry Pi Zero W. I added to it a Pimoroni BME680 Breakout sensor that can measure air quality, temperature, pressure and humidity.
To send the data to the Gateway, I am using the Python code below. This will send temperature, barometric pressure and humidity values to TTN. The sensor.set_temp_offset(offset) and display_data(-3) code allow compensating the temperature by +/- n degrees. I noticed that the temperature value may be a few degrees too high, especially if the sensor is in a box or close to a battery that generates heat.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from rak811.rak811 import Mode, Rak811
import bme680
import time
lora = Rak811()
lora.hard_reset()
time.sleep(2)
lora.mode = Mode.LoRaWan
lora.band = 'EU868'
lora.set_config(dev_eui='XXXXXXXXXXXXXXXX',
app_eui='XXXXXXXXXXXXXXXX',
app_key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
lora.join_otaa()
lora.dr = 5
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_4X)
sensor.set_temperature_oversample(bme680.OS_8X)
sensor.set_filter(bme680.FILTER_SIZE_3)
while True:
def display_data(offset=0):
sensor.set_temp_offset(offset)
if sensor.get_sensor_data():
Temp = int(10*round(sensor.data.temperature, 1))
Pression = int(10*round(sensor.data.pressure, 1))
HR = int(2*sensor.data.humidity)
display_data(-3)
lora.send(bytes.fromhex('0167{:04x}0273{:04x}0368{:02x}'.format(Temp, Pression, HR)))
time.sleep(15)
lora.close()
Data is sent to the Gateway and can be seen on the Live Data board.
Finally, I am using Datacake to visualise the data through a custom dashboard.
That’s it !
https://www.framboise314.fr/connecter-une-gateway-lora-rak833-a-ttn-v3/
https://www.hardill.me.uk/wordpress/2020/08/01/another-lora-temperature-humidity-sensor/?unapproved=28525&moderation-hash=625a6af01e4b6e29e7c066ecb3b2271d#comment-28525
https://learn.pimoroni.com/article/getting-started-with-bme680-breakout
https://docs.datacake.de/lorawan/using-cayenne-lpp
IoT Gateway HAT for Raspberry Pi
Raspberry Pi IoT LoRa pHAT
Raspberry Pi Zero W
Nebra IP67 Enclosure
Mounting Expansion Board
Pi PoE Switch HAT
PiJuice HAT
BME680 Sensor
Ublox NEO-6M GPS UART
Small GNSS Antenna (GPS)
How to assemble your HAT Holder for the Nebra IP67 Case