Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

Simple Sqlite logger for MQTT Brokers.

Project Description

mqttSqLite logger is a lightweight logger for MQTT brokers. It allows you to log all the published data under spectific topics and retrieve them for posterior data analysis.

The logger is totally managed over mqtt, so you can add, remove or query your topics without sql sintax.

Installation

The mqttSqLite logger is developed in python and use the peewee package as database provider and paho as mqtt client. In order to install the libraries you will need to install both libraries with:

pip install paho-mqtt peewee

after the package installation you need to add a private_settings.py file to your mqttSqlite logger file with the following information:

# Sqlite database file
DATABASE = 'mqtt.db'

# MQTT server settings
MQTT_HOST = 'YOUR_MQTT_SERVER_HOST'
MQTT_PORT = 'YOUR_MQTT_SERVER_PORT'

# Base logger topic
ROOT_TOPIC = 'house/logger/'

# password for management options
MANAGEMENT_PASSWORD = 'YOUR_PASSWORD_FOR_MANAGEMENT_OPTIONS'

# password for query options
QUERY_PASSWORD = 'YOUR_PASSWORD_FOR_QUERY_THE_LOG'

In order to run the logger you only have to execute the following command:

python mqtt_logger.py

Management commands (NOT IMPLEMENTED YET!!!)

In order to add or remove the topics to the logger you can execute the following commands from any mqtt client.

The command structure is always the same, first the ROOT_TOPIC defined in your private settings followed by the desired command. For instance based on the provided private settings file a valid command could be: house/logger/topic/add.

Included in the management commands payload should have included a json message with the following structure:

{
 "client" : "CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE"
 "password" : "YOUR_PASSWORD_FOR_MANAGEMENT_OPTIONS",
 "topic" : "TOPIC / ALL", #optional in some cases
 "option" : "COMMAND_OPTION", #optional in some cases
 }

The available commands related with topics managements are the following:

Command purpose
ROOT_TOPIC/topic/add add new topic to the logger
ROOT_TOPIC/topic/remove remove topic from to the logger
ROOT_TOPIC/topic/list remove topic from to the logger

The MqttSQlite logger will respond with a json with the following format:

{
 "client" : "CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE",
 "result" : "OK/KO",
 "error" : "MESSAGE WITH ERROR WHEN RESULT IS KO",
 "topics" : [
    "registered topic 1",
    "registered topic2",
    ...
    ]
 }

The commands related with logger content managements are the following:

Command purpose
ROOT_TOPIC/log/delete/last remove last entry por a topic (if included) or all topics
ROOT_TOPIC/log/delete/minut es remove the log entries older than x minutes (included in options) for a topic (if included) or all
ROOT_TOPIC/log/delete/hours remove the log entries older than x hours (included in options) for a topic (if included) or all
ROOT_TOPIC/log/delete/days remove the log entries older than x days (included in options) for a topic (if included) or all
ROOT_TOPIC/log/delete/all remove all entries for a topic (if included) or all topics

The MqttSqlite will respond with a json with the following structure:

{
 "client" : "CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE",
 "result" : "OK / KO"
 "error" : "MESSAGE WITH ERROR WHEN RESULT IS KO",
 }

Query Commands (NOT IMPLEMENTED YET!!!)

The query options structure are similar to the previous one. First the TOPIC_ROOTfollowed by the desired command. In the payload should be included a json with the following structure:

{
 "client" : "CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE",
 "password" : "YOUR_PASSWORD_FOR_MANAGEMENT_OPTIONS",
 "topic" : "TOPIC"
 "option" : "COMMAND_OPTION" #optional in some cases
 }

The complete list of available query commands is the following:

Command purpose
ROOT_TOPIC/log/query/last get the last entry for a topic
ROOT_TOPIC/log/query/minutes get the entries from the last x minutes
ROOT_TOPIC/log/query/hours get the entries from the last x hours
ROOT_TOPIC/log/query/days get the entries from the last x days

The MqttSqlite logger will respond in the same topic with the required information with the following json format:

{
 "client" : "CLIENT_NAME_USED_TO_IDENTIFY_THE_RESPONSE",
 "topic" : "TOPIC",
 "result" : "OK/KO",
 "error" : "MESSAGE WITH ERROR WHEN RESULT IS KO",
 "values" : [
    {"timestamp" : "YYYY-MM-ddTHH:mm:ss" , "value":"string_with_value"},
    ....]
 }
Release History

Release History

This version
History Node

1.7

History Node

1.6

History Node

1.5

History Node

1.4

History Node

1.3

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
MqttSqliteLogger-1.7.tar.gz (9.9 kB) Copy SHA256 Checksum SHA256 Source Jun 9, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting