MQTT listener to save data
Project description
MQTT subscriber
A service to listen for messages and save the data.
flowchart LR
publisher --> broker
broker --> subscriber
subscriber --> storage[(Storage)]
Installation
There is a Bash script to install this service: install.sh.
There are further details below.
Install Python package
Create a virtual environment
sudo mkdir -p /opt/balance-subscriber
sudo python3 -m venv /opt/balance-subscriber/venv
Activate the virtual environment
source /opt/balance-subscriber/venv/bin/activate
Install this package
pip install --upgrade balance-subscriber
Set up service
Create a service account called balance-subscriber.
sudo useradd --system balance-subscriber
This user must have permissions to write to the target data directory.
Install the systemd service.
cp --verbose ./systemd/balance-subscriber.service /etc/systemd/system/balance-subscriber.service
Reload all systemd unit files
sudo systemctl daemon-reload
Enable the service
sudo systemctl enable balance-subscriber.service
Configuration
Configure the service using the systemd configuration editor.
sudo systemctl edit balance-subscriber.service
This will create or edit an override configuration file in the directory /etc/systemd/system/balance-subscriber.service.d.
Edit this file to set the options for the service, such as the target data directory. Each row defines an environment variable containing a configuration setting for the service.
[Service]
Environment="DATA_DIR=/tmp"
Then, restart the service as described in the service control section.
Options
The following options are available.
| Setting | Required | Description | Default |
|---|---|---|---|
DATA_DIR |
Required | The path of the target directory to serialise MQTT messages to. | |
HOST |
Optional | MQTT broker host name | localhost |
PORT |
Optional | MQTT broker port | 1883 |
USERNAME |
Optional | MQTT broker username | |
PASSWORD |
Optional | MQTT broker password | |
TOPICS |
Optional | MQTT topics | # |
QOS |
Optional | Quality of service (0, 1, 2) | 0 |
KEEP_ALIVE |
Optional | MQTT broker keep-alive interval (time in seconds) | 60 |
LOG_LEVEL |
Optional | Logging verbosity | WARNING |
EXT |
Optional | File extension for saved messages | .bin |
These settings are specified in the configuration file for the systemd service as described above.
Usage
The app will run as a service in the background.
Service control
Start the service
sudo systemctl start balance-subscriber.service
Stop the service
sudo systemctl stop balance-subscriber.service
Restart the service
sudo systemctl restart balance-subscriber.service
Monitoring
View service status
sudo systemctl status balance-subscriber.service
View logs
sudo journalctl -u balance-subscriber.service --since "1 hour ago"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file balance_subscriber-1.0.1.tar.gz.
File metadata
- Download URL: balance_subscriber-1.0.1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a13b4a979da6f0acba72a3438688770808708cdfe13867ddf5af01ee94cc532
|
|
| MD5 |
5664ba9272aac1488f8da173a6198fb6
|
|
| BLAKE2b-256 |
26f928e68fd6cc5112d6be4e08472bd07098ca83e46840874b337791bedd0013
|
Provenance
The following attestation bundles were made for balance_subscriber-1.0.1.tar.gz:
Publisher:
publish.yaml on IoT-balance-project/balance-mqtt-subscriber
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
balance_subscriber-1.0.1.tar.gz -
Subject digest:
1a13b4a979da6f0acba72a3438688770808708cdfe13867ddf5af01ee94cc532 - Sigstore transparency entry: 162572776
- Sigstore integration time:
-
Permalink:
IoT-balance-project/balance-mqtt-subscriber@46d0c50f88752776feaccc653032f933be6dae6f -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/IoT-balance-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@46d0c50f88752776feaccc653032f933be6dae6f -
Trigger Event:
release
-
Statement type:
File details
Details for the file balance_subscriber-1.0.1-py3-none-any.whl.
File metadata
- Download URL: balance_subscriber-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e215e336d38876d9b5d831db3f5f4a68d35d7df77c18699bb816228fac16ab
|
|
| MD5 |
197b8741f3833677c9b0ac61d9ec752b
|
|
| BLAKE2b-256 |
b7b54920a07ec7a09ce0b026a54d908bc89dcd1f7096eef54f3b9432e2f6fa0f
|
Provenance
The following attestation bundles were made for balance_subscriber-1.0.1-py3-none-any.whl:
Publisher:
publish.yaml on IoT-balance-project/balance-mqtt-subscriber
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
balance_subscriber-1.0.1-py3-none-any.whl -
Subject digest:
23e215e336d38876d9b5d831db3f5f4a68d35d7df77c18699bb816228fac16ab - Sigstore transparency entry: 162572778
- Sigstore integration time:
-
Permalink:
IoT-balance-project/balance-mqtt-subscriber@46d0c50f88752776feaccc653032f933be6dae6f -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/IoT-balance-project
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@46d0c50f88752776feaccc653032f933be6dae6f -
Trigger Event:
release
-
Statement type: