David-Lor / MQTT2MongoDB

Store all incoming 🦟MQTT messages on 🍃MongoDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:
  • Docker recommended if available - you can use my Python Autoclonable App Docker

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

{
    "_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

About

Store all incoming 🦟MQTT messages on 🍃MongoDB

License:Apache License 2.0


Languages

Language:Python 100.0%