MQTT to SQLite Logger
Table of Contents
Description
mqtt-logger allows for asynchronous data logging of MQTT messages to a SQLite database. It also allows for the playback of previously recorded MQTT messages.
Installation
To install mqtt-logger you can simply use pip.
pip install mqtt-logger
Example Usage
Recording MQTT Messages
This example records messages to the test/# topic using a public MQTT broker. It will record for 10 seconds. If you are using a private broker, you may need to set the username and password parameters.
Example recorder taken from examples/10s_recording.py
import mqtt_logger
import os
import time
# Initalise mqtt recorder object
rec = mqtt_logger.Recorder(
sqlite_database_path=os.path.join(os.path.dirname(__file__), "MQTT_log.db"),
topics=["test/#"],
broker_address="broker.hivemq.com",
verbose=True,
## Uncomment for TLS connection
# port=8883,
# use_tls=True,
# tls_insecure=False,
## Uncomment for username and password
# username="username",
# password="password",
)
# Start the logger, wait 10 seconds and stop the logger
rec.start()
time.sleep(10)
rec.stop()
Playback Recorded MQTT Messages
This example plays back previously recorded MQTT messages from mqtt_logger.Recorder. If you are using a private
broker, you may need to set the username and password parameters.
Example recorder taken from examples/10s_playback.py
import mqtt_logger
import os
# Initalise playback object
playback = mqtt_logger.Playback(
sqlite_database_path=os.path.join(os.path.dirname(__file__), "MQTT_log.db"),
broker_address="broker.hivemq.com",
verbose=True,
)
# Start playback at 2x speed (twice as fast)
playback.play(speed=2)
Database
The SQLite database has two tables called LOG and RUN. The LOG table contains the messages that are being logged. The RUN table contains the information about the current run of the program.
LOG Table
| ROW NAME | DESCRIPTION |
|---|---|
| ID | Unique number assigned to each message (ascending int) |
| RUN_ID | ID of the current run (ascending int) |
| UNIX_TIME | Time when the message was received |
| TOPIC | MQTT topic |
| MESSAGE | MQTT message received |
RUN Table
| ROW NAME | DESCRIPTION |
|---|---|
| ID | Unique number assigned to run (ascending int) |
| START_UNIX_TIME | Time when logger was started |
| END_UNIX_TIME | Time when logger was stopped |
Metadata
Release files for mqtt_logger 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mqtt_logger-0.3.6.tar.gz | 6.9 kB | Without provenance | Details for mqtt_logger-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mqtt_logger-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for mqtt_logger-0.3.6-py3-none-any.whl |
Total release size: 14.8 kB
Release files / mqtt_logger-0.3.6.tar.gz
| Download URL | mqtt_logger-0.3.6.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f834f03fe570c7ab642bd475ff5509eb39140259eb4d73a6c5cb2e2ba3ca839d
|
|
BLAKE2b-256 checksum How to use checksums |
3bdc9fb8e513fdd303aac1e8124e63eec69beb9c243e5c906c94636fe1bf3de4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1021-azure
|
Release files / mqtt_logger-0.3.6-py3-none-any.whl
| Download URL | mqtt_logger-0.3.6-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c45b33e4cec4ed8576c067da6ed36fb52cfba06589f6225493eb0896f2aed72
|
|
BLAKE2b-256 checksum How to use checksums |
60734fcab986dbfc789106d4eb20146648f63b6e419ec2fd75133c17afe367fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.19 Linux/6.5.0-1021-azure
|
Security for mqtt_logger 0.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.