Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
/ MQTT2MongoDB Public archive

Store all incoming 🦟MQTT messages on 🍃MongoDB

License

Notifications You must be signed in to change notification settings

David-Lor/MQTT2MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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