Microcontroller projects

LoRa to MQTT Gateway

last updated: 2024-02-26

Quick links

Introduction

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.

lora 2 mqtt

Hardware

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.


lora2mqtt circuit

Software

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

We software sends an alive message in MQTT every minute:
all messages

The software needs external libraries to work:

They can be installed in the Arduino IDE.

The board can also be programmed via OTA.

Downloads

Everything is on github: https://github.com/weigu1/lora2mqtt_ethernet_gw.

Interesting links