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.
- 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
- Docker and Docker Compose installed on your system
- A Raspberry Pi with a LoRa radio connected to
ttyS0
- An MQTT broker to receive data
- 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
git clone https://github.com/Mawiguk0/lora-mqtt-bridge.git
cd lora-mqtt-bridge
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 the Docker image:
docker build -t lora-monitor .
-
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
You can check the status of your container and health checks using:
sudo docker-compose ps
To see the logs generated by the container, use:
sudo docker-compose logs
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.
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 runningrequirements.txt
: Python dependencies.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to submit issues and pull requests. Contributions are welcome!
- Special Thanks to Basor Dali, your project helped my bootstrap this one https://github.com/basor-dali/SX126X_LoRa_HAT_rasp_pi
- Thanks to the open-source community for providing the tools and libraries used in this project.
If you have any questions or need further assistance, please open an issue in this repository.