This project sets up an MQTT broker using Eclipse Mosquitto and logs MQTT messages into a MySQL database. All services are containerized with Docker for easy setup and distribution.
- Docker and Docker Compose installed
- Python 3.x
- Clone the repository.
git clone https://github.com/sanlega/mqtt-server-tests
- Change into the project directory.
cd mqtt-server-tests
- Start the Docker containers.
docker-compose up -d
- Run the Python script to create the MySQL table.
python create_table.py
To start the MQTT Data Logger:
python mqtt_data_logger.py
Test. Use a variation of this command with your host to make sure it works:
mosquitto_pub -h 127.0.0.1 -t topic -m "Hello"
Once the MQTT broker is running, you can publish messages to the topic test/#
(or any topic you've configured). The messages will be logged into the MySQL database.
mqtt_data_logger.py
: Main script that subscribes to MQTT topics and logs messages into MySQL.create_table.py
: Python script to create the MySQL table if it doesn't exist.docker-compose.yml
: Docker Compose file to set up Mosquitto and MySQL.mosquitto.conf
: Configuration file for the Mosquitto MQTT broker.
This is a work-in-progress, and contributions are welcome. Please open an issue or submit a pull request.