Store all incoming 🦟MQTT messages on 🐬MySQL/MariaDB
APACHE-2.0 License
A simple Python project that listen to one or more MQTT topics and save all the incoming messages on a MySQL/MariaDB database, as some sort of logger.
Settings for both MQTT client and MySQL/MariaDB database server must be properly set using env variables or using .env files.
The full list of variables is located on the sample.env
file, which can be modified to customize these settings.
If you want to set these variables through this file, it must be renamed to .env
.
Otherwise, just set them as system env variables (recommended when using Docker).
Python modules include fallback default values in case env-variable values are not defined, or a .env
file is not available, which are the same as showing on the sample.env
file.
However, SQL_USER
, SQL_DATABASE
and SQL_PASSWORD
don't have default values and must be defined.
This is the most preferred way to run MQTT2MySQL, if Docker is available.
docker run -d -e GIT_REPOSITORY:https://github.com/David-Lor/MQTT2MySQL.git -e SQL_USER:root -e SQL_PASSWORD:1234 -e SQL_DATABASE:mqtt --name mqtt2mysql davidlor/python-autoclonable-app
IMPORTANT: Set all the required env variables with the -e
option, following the examples provided above.
This is the most preferred way to run MQTT2MySQL, if Docker is unavailable.
git clone https://github.com/David-Lor/MQTT2MySQL.git
# Rename and modify the .env file
mv MQTT2MySQL/sample.env MQTT2MySQL/.env
nano MQTT2MySQL/.env
# Run the app
python MQTT2MySQL
IMPORTANT: Rename the sample.env
file to .env
and properly et the variables inside.
This has not been tested.
git clone https://github.com/David-Lor/MQTT2MySQL.git
# Set your env variables system-wide
# Install
cd MQTT2MySQL
python setup.py install
# Run
mqtt2mysql