{ "info": { "author": "Roberto Diaz Ortega", "author_email": "info@rdiaz.es", "bugtrack_url": null, "classifiers": [], "description": "mqttSqLite logger\r\n=================\r\n\r\nmqttSqLite logger is a lightweight logger for MQTT brokers. It allows\r\nyou to log all the published data under spectific topics and retrieve\r\nthem for posterior data analysis.\r\n\r\nThe logger is totally managed over mqtt, so you can add, remove or query\r\nyour topics without sql sintax.\r\n\r\nInstallation and run\r\n--------------------\r\n\r\nThe mqttSqLite logger is developed in python and use the peewee package\r\nas database provider and paho as mqtt client. In order to install the\r\nlogger you need pip installed in your computer, and you only need to\r\nexecute the following command:\r\n\r\n::\r\n\r\n pip install MqttSqliteLogger\r\n\r\nMqttsqlite support some comand line arguments that allows the the logger\r\nconfiguration according to your needs. The supported commands are the\r\nfollowing:\r\n\r\n+----------------+-------------+-------------------------------+\r\n| Command | Default | Purpose |\r\n+================+=============+===============================+\r\n| --host | localhost | mqtt broker host |\r\n+----------------+-------------+-------------------------------+\r\n| --port | 1883 | mqtt broker port |\r\n+----------------+-------------+-------------------------------+\r\n| --root | logger/ | mqtt base topic for logger |\r\n+----------------+-------------+-------------------------------+\r\n| --mgpassword | admin1234 | management options password |\r\n+----------------+-------------+-------------------------------+\r\n| --qrpassword | query1234 | query options password |\r\n+----------------+-------------+-------------------------------+\r\n\r\nThe logger can be started as:\r\n\r\n::\r\n\r\n mqttsqlite --host your_host --port your_port\r\n\r\nOnce you run the logger with the options, you can save them in next runs\r\nbecause the logger saves the options inside the database, so after\r\nconfiguration changed you can launch the mqttsqlite logger simply as:\r\n\r\n::\r\n\r\n mqttsqlite\r\n\r\nManagement commands\r\n-------------------\r\n\r\nIn order to add or remove the topics to the logger you can execute the\r\nfollowing commands from any mqtt client.\r\n\r\nThe command structure is always the same, first the ``ROOT_TOPIC``\r\ndefined through the root option when launch the logger followed by the\r\ndesired command. For instance based a valid command could be:\r\n``logger/topic/add``.\r\n\r\nIncluded in the management commands payload should have included a json\r\nmessage with the following structure:\r\n\r\n::\r\n\r\n {\r\n \"client\" : \"CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE\"\r\n \"password\" : \"YOUR_PASSWORD_FOR_MANAGEMENT_OPTIONS\",\r\n \"topic\" : \"TOPIC / ALL\", #optional in some cases\r\n \"option\" : \"COMMAND_OPTION\", #optional in some cases\r\n }\r\n\r\nThe available commands related with topics managements are the\r\nfollowing:\r\n\r\n+----------------------------+-----------------------------------+\r\n| Command | purpose |\r\n+============================+===================================+\r\n| ROOT\\_TOPIC/topic/add | add new topic to the logger |\r\n+----------------------------+-----------------------------------+\r\n| ROOT\\_TOPIC/topic/remove | remove topic from to the logger |\r\n+----------------------------+-----------------------------------+\r\n| ROOT\\_TOPIC/topic/list | remove topic from to the logger |\r\n+----------------------------+-----------------------------------+\r\n\r\nThe MqttSQlite logger will respond in a new topic called\r\n``ROOT_TOPIC/response`` with a json with the following format:\r\n\r\n::\r\n\r\n {\r\n \"client\" : \"CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE\",\r\n \"result\" : \"OK/KO\",\r\n \"error\" : \"MESSAGE WITH ERROR WHEN RESULT IS KO\",\r\n \"topics\" : [\r\n \"registered topic 1\",\r\n \"registered topic2\",\r\n ...\r\n ]\r\n }\r\n\r\nThe commands related with logger content managements are the following:\r\n\r\n+------------------------------+---------------------+\r\n| Command | purpose |\r\n+==============================+=====================+\r\n| ROOT\\_TOPIC/log/delete/last | remove last entry |\r\n| | por a topic (if |\r\n| | included) or all |\r\n| | topics |\r\n+------------------------------+---------------------+\r\n| ROOT\\_TOPIC/log/delete/minut | remove the log |\r\n| es | entries older than |\r\n| | x minutes (included |\r\n| | in options) for a |\r\n| | topic (if included) |\r\n| | or all |\r\n+------------------------------+---------------------+\r\n| ROOT\\_TOPIC/log/delete/hours | remove the log |\r\n| | entries older than |\r\n| | x hours (included |\r\n| | in options) for a |\r\n| | topic (if included) |\r\n| | or all |\r\n+------------------------------+---------------------+\r\n| ROOT\\_TOPIC/log/delete/days | remove the log |\r\n| | entries older than |\r\n| | x days (included in |\r\n| | options) for a |\r\n| | topic (if included) |\r\n| | or all |\r\n+------------------------------+---------------------+\r\n\r\nThe MqttSqlite will respond in the topic ``ROOT_TOPIC/response`` with a\r\njson with the following structure:\r\n\r\n::\r\n\r\n {\r\n \"client\" : \"CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE\",\r\n \"result\" : \"OK / KO\"\r\n \"error\" : \"MESSAGE WITH ERROR WHEN RESULT IS KO\",\r\n }\r\n\r\nQuery Commands\r\n--------------\r\n\r\nThe query options structure are similar to the previous one. First the\r\n``TOPIC_ROOT``\\ followed by the desired command. In the payload should\r\nbe included a json with the following structure:\r\n\r\n::\r\n\r\n {\r\n \"client\" : \"CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE\",\r\n \"password\" : \"YOUR_PASSWORD_FOR_MANAGEMENT_OPTIONS\",\r\n \"topic\" : \"TOPIC\"\r\n \"option\" : \"COMMAND_OPTION\" #optional in some cases\r\n }\r\n\r\nThe complete list of available query commands is the following:\r\n\r\n+---------------------------------+-------------------------------------------+\r\n| Command | purpose |\r\n+=================================+===========================================+\r\n| ROOT\\_TOPIC/log/query/last | get the last entry for a topic |\r\n+---------------------------------+-------------------------------------------+\r\n| ROOT\\_TOPIC/log/query/minutes | get the entries from the last x minutes |\r\n+---------------------------------+-------------------------------------------+\r\n| ROOT\\_TOPIC/log/query/hours | get the entries from the last x hours |\r\n+---------------------------------+-------------------------------------------+\r\n| ROOT\\_TOPIC/log/query/days | get the entries from the last x days |\r\n+---------------------------------+-------------------------------------------+\r\n\r\nThe MqttSqlite logger will respond in the topic ``ROOT_TOPIC/response``\r\nwith the required information with the following json format:\r\n\r\n::\r\n\r\n {\r\n \"client\" : \"CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE\",\r\n \"topic\" : \"TOPIC\",\r\n \"result\" : \"OK/KO\",\r\n \"error\" : \"MESSAGE WITH ERROR WHEN RESULT IS KO\",\r\n \"values\" : [\r\n {\"timestamp\" : \"YYYY-MM-ddTHH:mm:ss\" , \"value\":\"string_with_value\"},\r\n ....]\r\n }\r\n\r\nExamples\r\n--------\r\n\r\nFollowing is a python code using pahoo-mqtt client to communicate with\r\nthe logger in order to add a new topic to be followed by the logger:\r\n\r\nAdd topic\r\n~~~~~~~~~\r\n\r\n::\r\n\r\n import paho.mqtt.client as mqtt\r\n import json\r\n\r\n MANAGEMENT_PASSWORD = 'YOUR PASSWORD'\r\n MQTT_HOST = 'YOUR HOST'\r\n MQTT_PORT = 'YOUR PORT'\r\n ROOT_TOPIC = 'YOUR ROOT LOGGER TOPIC by default logger/'\r\n desired_topic = 'desired/new/topic'\r\n\r\n payload = {}\r\n payload['client'] = 'simple_example'\r\n payload['topic'] = desired_topic\r\n payload['password'] = MANAGEMENT_PASSWORD\r\n\r\n\r\n def on_connect(client, userdata, flags, rc):\r\n client_topic = ROOT_TOPIC + 'topic/add'\r\n client.subscribe(ROOT_TOPIC + 'response') #important subscribe to response topic to get the command result\r\n client.publish(client_topic, json.dumps(payload))\r\n\r\n\r\n\r\n def on_message(client, userdata, msg):\r\n \r\n received_data = json.loads(msg.payload)\r\n print(received_data)\r\n if 'client' in received_data:\r\n if received_data['client'] == payload['client']:\r\n print('Received Meesage from Logger: ')\r\n print(received_data)\r\n\r\n client = mqtt.Client()\r\n client.on_connect = on_connect\r\n client.on_message = on_message\r\n\r\n client.connect(MQTT_HOST, MQTT_PORT, 60)\r\n\r\n client.loop_forever()\r\n\r\nRunning this script you will get a similar output to the following:\r\n\r\n::\r\n\r\n Received Meesage from Logger:\r\n {u'topic': u'desired_topic', u'topics': [u'desired_topic'], u'client': u'simple_exampl\r\n e', u'result': u'OK'}\r\n\r\nQuery Topic\r\n~~~~~~~~~~~\r\n\r\nIn the following simple example, a topic query will be executed\r\nobtaining the topic information for the last 20 minutes:\r\n\r\n::\r\n\r\n import paho.mqtt.client as mqtt\r\n import json\r\n import mqttsqlite.settings.private_settings as Settings\r\n\r\n QUERY_PASSWORD = 'YOUR PASSWORD'\r\n MQTT_HOST = 'YOUR HOST'\r\n MQTT_PORT = 'YOUR PORT'\r\n ROOT_TOPIC = 'YOUR ROOT LOGGER TOPIC by default logger/'\r\n desired_topic = 'desired/new/topic'\r\n\r\n payload = {}\r\n payload['client'] = 'simple_example'\r\n payload['topic'] = desired_topic\r\n payload['options'] = 20\r\n payload['password'] = QUERY_PASSWORD\r\n\r\n\r\n def on_connect(client, userdata, flags, rc):\r\n client_topic = ROOT_TOPIC + 'log/query/minutes'\r\n client.subscribe(ROOT_TOPIC + 'response') #importanat subscribe to response topic before request to the logger\r\n client.publish(client_topic, json.dumps(payload))\r\n\r\n\r\n def on_message(client, userdata, msg):\r\n received_data = json.loads(msg.payload)\r\n if 'client' in received_data:\r\n if received_data['client'] == payload['client']:\r\n print('Received Meesage from Logger: ')\r\n print(received_data)\r\n client.disconnect()\r\n\r\n client = mqtt.Client()\r\n client.on_connect = on_connect\r\n client.on_message = on_message\r\n\r\n client.connect(MQTT_HOST, MQTT_PORT, 60)\r\n\r\n client.loop_forever()\r\n\r\nThe response obtained could be similar to the following:\r\n\r\n::\r\n\r\n Received Meesage from Logger:\r\n {u'topic': u'desired_topic', u'client': u'simple_example', u'values': [{u'timestamp':\r\n u'2017-06-09 22:55:21', u'value': u'71'}, {u'timestamp': u'2017-06-09 22:56:14', u'val\r\n ue': u'74'}, {u'timestamp': u'2017-06-09 22:56:15', u'value': u'74'}], u'result': u'OK\r\n '}", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/rdiaz82/mqttSqlLite", "keywords": "", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "MqttSqliteLogger", "package_url": "https://pypi.org/project/MqttSqliteLogger/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/MqttSqliteLogger/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/rdiaz82/mqttSqlLite" }, "release_url": "https://pypi.org/project/MqttSqliteLogger/1.0/", "requires_dist": null, "requires_python": null, "summary": "Simple Sqlite logger for MQTT Brokers.", "version": "1.0" }, "last_serial": 2939454, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "ab9af76317f635d2f3198cda3f5dfcc3", "sha256": "5abd1e4192793e5c98dc51aa3da6f898539b3705c89b624419e17eb8673fd92a" }, "downloads": -1, "filename": "MqttSqliteLogger-1.0.tar.gz", "has_sig": false, "md5_digest": "ab9af76317f635d2f3198cda3f5dfcc3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11610, "upload_time": "2017-06-09T22:24:12", "url": "https://files.pythonhosted.org/packages/bc/91/453b96393e961ba9b85783ab480476b22f1b4a101d9bc1cd1dcf5511ad8d/MqttSqliteLogger-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ab9af76317f635d2f3198cda3f5dfcc3", "sha256": "5abd1e4192793e5c98dc51aa3da6f898539b3705c89b624419e17eb8673fd92a" }, "downloads": -1, "filename": "MqttSqliteLogger-1.0.tar.gz", "has_sig": false, "md5_digest": "ab9af76317f635d2f3198cda3f5dfcc3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11610, "upload_time": "2017-06-09T22:24:12", "url": "https://files.pythonhosted.org/packages/bc/91/453b96393e961ba9b85783ab480476b22f1b4a101d9bc1cd1dcf5511ad8d/MqttSqliteLogger-1.0.tar.gz" } ] }