https://github.com/David-Lor/MQTT2MongoDB
Store all incoming 🦟MQTT messages on 🍃MongoDB
https://github.com/David-Lor/MQTT2MongoDB
log logging mongo mongodb mqtt mqtt-client mqtt-logger paho-mqtt paho-mqtt-python python python3 python36 python37
Last synced: 5 months ago
JSON representation
Store all incoming 🦟MQTT messages on 🍃MongoDB
- Host: GitHub
- URL: https://github.com/David-Lor/MQTT2MongoDB
- Owner: David-Lor
- License: apache-2.0
- Archived: true
- Created: 2019-03-08T21:43:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-01T02:23:25.000Z (almost 5 years ago)
- Last Synced: 2023-03-04T01:48:36.164Z (about 3 years ago)
- Topics: log, logging, mongo, mongodb, mqtt, mqtt-client, mqtt-logger, paho-mqtt, paho-mqtt-python, python, python3, python36, python37
- Language: Python
- Size: 8.79 KB
- Stars: 17
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-mqtt - mqtt2mongodb - Subscribe to MQTT topics and insert into MongoDB. (Interfaces / Logging)
README
# MQTT2MongoDB
A simple Python project that listen to one or more MQTT topics and save all the incoming messages on a MongoDB database, as some sort of logger.
## Requirements
- Python 3.x (tested on 3.7)
- Linux (not tested on other OS)
- A working, available MQTT broker
- A working, available MongoDB server
- Libraries:
* [pymongo](http://api.mongodb.com/python/current/)
* [paho-mqtt](https://pypi.org/project/paho-mqtt/)
- Docker recommended if available - you can use my [Python Autoclonable App Docker](https://hub.docker.com/r/davidlor/python-autoclonable-app/)
## Settings
Settings for MQTT and MongoDB can be placed on the mqtt.py and mongo.py files respectively, on a top-level UPPERCASE variables.
Alternatively, environment variables with the same names as these UPPERCASE variables are fetched instead of these variables, when available. This can be useful when running the app from a Docker container.
## Queue
(TODO) When the MongoDB server is unavailable or the insert failed, messages are stored on a list and periodically try to be inserted on the MongoDB again.
## Format of a Mongo document
```json
{
"_id": "5c82de0799ec3656ff38d215",
"topic": "home/test",
"payload": "This is a test!",
"qos": 2,
"timestamp": 1552080391,
"datetime": "08/03/2019 22:26:31"
}
```
## TODO
- Implement Queue
- Get timestamp of received messages right when they arrive