Mawiguk0 / lora-mqtt-bridge

A simple but effective dockerized bridge between LoRa and mqtt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serial LoRa MQTT Bridge Docker

This project demonstrates how to monitor a LoRa radio connected via a serial port to a Raspberry Pi and periodically send temperature and uptime information using MQTT. The project is containerized using Docker for easy deployment and management. The Project is tested with a Raspberry Pi 3B+ and the Waveshare SX1262 868 MHz LoRa-HAT. There is little to nothing that should prohibit usage with other serial connected devices.

Features

  • Reads data from a LoRa radio via a serial connection
  • Sends data to an MQTT broker
  • Periodically sends the Raspberry Pi's temperature and the container's uptime to the MQTT broker
  • Healthchecks to ensure reliable operation

Prerequisites

  • Docker and Docker Compose installed on your system
  • A Raspberry Pi with a LoRa radio connected to ttyS0
  • An MQTT broker to receive data

Getting Started

  • Connect the HAt to your Pi
  • Setup the serial interface with raspi-config -> Interface Options -> Serial Port -> No -> Yes -> OK
  • Setup a MQTT Broker or use the docker-compose-broker.yml

Clone the Repository

git clone https://github.com/Mawiguk0/lora-mqtt-bridge.git
cd lora-mqtt-bridge

Environment Variables

The application uses the following environment variables, which you can set in a .env file or directly in your docker-compose.yml file:

  • MQTT_SERVER: The address of your MQTT broker (default: 192.168.178.74)
  • MQTT_PORT: The port of your MQTT broker (default: 1883)
  • MQTT_TOPIC: The MQTT topic for LoRa data (default: /lora/)
  • TEMPERATURE_TOPIC: The MQTT topic for temperature data (default: bridge/temperature)
  • UPTIME_TOPIC: The MQTT topic for uptime data (default: bridge/uptime)
  • SERIAL_URL: The URL of the serial device (default: /dev/ttyS0)
  • SERIAL_BAUDRATE: The baud rate for the serial connection (default: 9600)
  • SLEEP_INTERVAL: The Interval of seconds to wait between temperature and uptime mqtt message (default: 60)

Build and Run the Docker Container

  1. Build the Docker image:

    docker build -t lora-monitor .
  2. Run the container using Docker Compose:

    docker-compose up -d

You can also run following to build and start the broker included docker-compose-broker.yml

docker compose -f docker-compose-broker.yml up -d --build

Check the Container Status

You can check the status of your container and health checks using:

sudo docker-compose ps

Accessing Logs

To see the logs generated by the container, use:

sudo docker-compose logs

Healthcheck

The container includes a healthcheck script that verifies:

  • MQTT connection is established
  • Serial connection is established

If either of these checks fail, the container will be marked as unhealthy.

File Structure

  • main.py: The main script that reads from the serial port and sends data to the MQTT broker.
  • healthcheck.sh: A script to check the health of the container.
  • Dockerfile: The Dockerfile to build the Docker image.
  • docker-compose.yml: Docker Compose configuration file.
  • docker-compose-broker.yml: Docker Compose configuration file with a mqtt broker up and running
  • requirements.txt: Python dependencies.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to submit issues and pull requests. Contributions are welcome!

Acknowledgments

Contact

If you have any questions or need further assistance, please open an issue in this repository.

About

A simple but effective dockerized bridge between LoRa and mqtt

License:MIT License


Languages

Language:Python 81.2%Language:Dockerfile 10.6%Language:Shell 8.2%