# MQTT to SQLite Logger
[![PyPI version](https://badge.fury.io/py/mqtt-logger.svg)](https://badge.fury.io/py/mqtt-logger)
[![Unit Tests](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-test.yml/badge.svg)](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-test.yml)
[![Upload Python Package](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-publish.yml)
[![codecov](https://codecov.io/github/Blake-Haydon/mqtt-logger/graph/badge.svg?token=8PA3F5RWXA)](https://codecov.io/github/Blake-Haydon/mqtt-logger)
## Table of Contents
- [MQTT to SQLite Logger](#mqtt-to-sqlite-logger)
- [Table of Contents](#table-of-contents)
- [Description](#description)
- [Installation](#installation)
- [Example Usage](#example-usage)
- [Recording MQTT Messages](#recording-mqtt-messages)
- [Playback Recorded MQTT Messages](#playback-recorded-mqtt-messages)
- [Database](#database)
- [`LOG` Table](#log-table)
- [`RUN` Table](#run-table)
## 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`.
```bash
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.
<!-- poetry run python examples/10s_recording.py -->
_Example recorder taken from [examples/10s_recording.py](examples/10s_recording.py)_
```python
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.
<!-- poetry run python examples/10s_playback.py -->
_Example recorder taken from [examples/10s_playback.py](examples/10s_playback.py)_
```python
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 |
---
Raw data
{
"_id": null,
"home_page": "https://github.com/Blake-Haydon/mqtt-logger",
"name": "mqtt_logger",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.7",
"maintainer_email": null,
"keywords": "MQTT, SQLite3",
"author": "Blake Haydon",
"author_email": "blake.a.haydon@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3b/dc/9fb8e513fdd303aac1e8124e63eec69beb9c243e5c906c94636fe1bf3de4/mqtt_logger-0.3.6.tar.gz",
"platform": null,
"description": "# MQTT to SQLite Logger\n\n[![PyPI version](https://badge.fury.io/py/mqtt-logger.svg)](https://badge.fury.io/py/mqtt-logger)\n[![Unit Tests](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-test.yml/badge.svg)](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-test.yml)\n[![Upload Python Package](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-publish.yml/badge.svg)](https://github.com/Blake-Haydon/mqtt-logger/actions/workflows/python-publish.yml)\n[![codecov](https://codecov.io/github/Blake-Haydon/mqtt-logger/graph/badge.svg?token=8PA3F5RWXA)](https://codecov.io/github/Blake-Haydon/mqtt-logger)\n\n## Table of Contents\n\n- [MQTT to SQLite Logger](#mqtt-to-sqlite-logger)\n - [Table of Contents](#table-of-contents)\n - [Description](#description)\n - [Installation](#installation)\n - [Example Usage](#example-usage)\n - [Recording MQTT Messages](#recording-mqtt-messages)\n - [Playback Recorded MQTT Messages](#playback-recorded-mqtt-messages)\n - [Database](#database)\n - [`LOG` Table](#log-table)\n - [`RUN` Table](#run-table)\n\n## Description\n\n`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.\n\n## Installation\n\nTo install `mqtt-logger` you can simply use `pip`.\n\n```bash\npip install mqtt-logger\n```\n\n## Example Usage\n\n### Recording MQTT Messages\n\nThis 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.\n\n<!-- poetry run python examples/10s_recording.py -->\n\n_Example recorder taken from [examples/10s_recording.py](examples/10s_recording.py)_\n\n```python\nimport mqtt_logger\nimport os\nimport time\n\n# Initalise mqtt recorder object\nrec = mqtt_logger.Recorder(\n sqlite_database_path=os.path.join(os.path.dirname(__file__), \"MQTT_log.db\"),\n topics=[\"test/#\"],\n broker_address=\"broker.hivemq.com\",\n verbose=True,\n\n ## Uncomment for TLS connection\n # port=8883,\n\t# use_tls=True,\n\t# tls_insecure=False,\n\n ## Uncomment for username and password\n # username=\"username\",\n # password=\"password\",\n)\n\n# Start the logger, wait 10 seconds and stop the logger\nrec.start()\ntime.sleep(10)\nrec.stop()\n```\n\n### Playback Recorded MQTT Messages\n\nThis example plays back previously recorded MQTT messages from `mqtt_logger.Recorder`. If you are using a private\nbroker, you may need to set the `username` and `password` parameters.\n\n<!-- poetry run python examples/10s_playback.py -->\n\n_Example recorder taken from [examples/10s_playback.py](examples/10s_playback.py)_\n\n```python\nimport mqtt_logger\nimport os\n\n# Initalise playback object\nplayback = mqtt_logger.Playback(\n sqlite_database_path=os.path.join(os.path.dirname(__file__), \"MQTT_log.db\"),\n broker_address=\"broker.hivemq.com\",\n verbose=True,\n)\n\n# Start playback at 2x speed (twice as fast)\nplayback.play(speed=2)\n```\n\n## Database\n\nThe 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.\n\n### `LOG` Table\n\n| ROW NAME | DESCRIPTION |\n| --------- | ------------------------------------------------------ |\n| ID | Unique number assigned to each message (ascending int) |\n| RUN_ID | ID of the current run (ascending int) |\n| UNIX_TIME | Time when the message was received |\n| TOPIC | MQTT topic |\n| MESSAGE | MQTT message received |\n\n---\n\n### `RUN` Table\n\n| ROW NAME | DESCRIPTION |\n| --------------- | --------------------------------------------- |\n| ID | Unique number assigned to run (ascending int) |\n| START_UNIX_TIME | Time when logger was started |\n| END_UNIX_TIME | Time when logger was stopped |\n\n---\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python based MQTT to SQLite3 logger",
"version": "0.3.6",
"project_urls": {
"Homepage": "https://github.com/Blake-Haydon/mqtt-logger"
},
"split_keywords": [
"mqtt",
" sqlite3"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "60734fcab986dbfc789106d4eb20146648f63b6e419ec2fd75133c17afe367fd",
"md5": "66639ca3c35bc2f8c378590a67da8eab",
"sha256": "7c45b33e4cec4ed8576c067da6ed36fb52cfba06589f6225493eb0896f2aed72"
},
"downloads": -1,
"filename": "mqtt_logger-0.3.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "66639ca3c35bc2f8c378590a67da8eab",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.7",
"size": 7935,
"upload_time": "2024-05-18T00:10:01",
"upload_time_iso_8601": "2024-05-18T00:10:01.701284Z",
"url": "https://files.pythonhosted.org/packages/60/73/4fcab986dbfc789106d4eb20146648f63b6e419ec2fd75133c17afe367fd/mqtt_logger-0.3.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3bdc9fb8e513fdd303aac1e8124e63eec69beb9c243e5c906c94636fe1bf3de4",
"md5": "5af2f377f4f2f29dd178da2438805f14",
"sha256": "f834f03fe570c7ab642bd475ff5509eb39140259eb4d73a6c5cb2e2ba3ca839d"
},
"downloads": -1,
"filename": "mqtt_logger-0.3.6.tar.gz",
"has_sig": false,
"md5_digest": "5af2f377f4f2f29dd178da2438805f14",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.7",
"size": 6887,
"upload_time": "2024-05-18T00:10:03",
"upload_time_iso_8601": "2024-05-18T00:10:03.941087Z",
"url": "https://files.pythonhosted.org/packages/3b/dc/9fb8e513fdd303aac1e8124e63eec69beb9c243e5c906c94636fe1bf3de4/mqtt_logger-0.3.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-18 00:10:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Blake-Haydon",
"github_project": "mqtt-logger",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "mqtt_logger"
}