last updated: 2024-02-26
In house automation MQTT is a quasi standard. We could use LoRaWAN with a TTN gateway. The TTN stack can work as an MQTT server, but the overhead is really big. For security reasons I like to use my own gear without internet access. So I chose an Olimex board with an ESP32 and Ethernet POE port to realise an LoRa to MQTT gateway.
I use this OLIMEX ESP32-POE board
. These boards have an Universal EXTension (UEXT) connector providing SPI for the SX1276 breakout board.
I had problems by using GPIO2, so here is the circuit for our Gateway. The library works also without RESET.
In the beginning of the code we have a bunch of defines:
/****** Defines to costumize the gateway ******/
//#define USE_SECRETS // if secrets config in lib folder
//#define SHOW_ALL_LORA_MESSAGES // normally only msgs 1 byte = GATEWAY_ADDR
#define DEBUG_SERIAL
#define DEBUG_UDP
#define USE_AES128_GCM
//#define USE_MQTT_SECURITY
#define NURSING // BTS-IoT student real live project
USE_SECRETS
The software normally uses a file named config.h
in the same directory then the skcetch directory. You must configure your passwords, IP addresses, topics etc. in this file, so it is safer to place it elsewhere and not give away your secrets while charing the sketch. If USE_SECRETS
is defined a file named "secretsxxx.h" has to be placed in a sketchbook libraries folder. Create a folder named "Secrets" in sketchbook/libraries and copy the config.h file there. Rename it to secretsxxx.h (here secrets_lora_2_mqtt_gateway.h
) and delete the original config file.
SHOW_ALL_LORA_MESSAGES
sends all LoRa messages to MQTT with no regard to the gateway address (first byte; normally 0xFE).
DEBUG_SERIAL
Debug everything to Serial (Serial0, e,g, serial monitor).
DEBUG_UDP
Debug everything to a PC via UDP. The IP address and port are in config.h
USE_AES128_GCM
The incoming LoRa stream is encrypted with AES128-GCM. Decrypt the message with key etc in config.h
.
USE_MQTT_SECURITY
Use a password, topic Prefix and preshared key to connect with the MQTT server (config.h
).
NURSING
Interpret the data as defined in the Nursing project. The Nursing project is a BTS-IoT student real live project from 2024.
We software sends an alive message in MQTT every minute:
The software needs external libraries to work:
They can be installed in the Arduino IDE.
The board can also be programmed via OTA.
Everything is on github: https://github.com/weigu1/lora2mqtt_ethernet_gateway.