Skip to main content

MQTT listener to save data

Project description

Tests

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


Download files

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

Source Distribution

balance_subscriber-1.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

balance_subscriber-1.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for balance_subscriber-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1a13b4a979da6f0acba72a3438688770808708cdfe13867ddf5af01ee94cc532
MD5 5664ba9272aac1488f8da173a6198fb6
BLAKE2b-256 26f928e68fd6cc5112d6be4e08472bd07098ca83e46840874b337791bedd0013

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file balance_subscriber-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for balance_subscriber-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23e215e336d38876d9b5d831db3f5f4a68d35d7df77c18699bb816228fac16ab
MD5 197b8741f3833677c9b0ac61d9ec752b
BLAKE2b-256 b7b54920a07ec7a09ce0b026a54d908bc89dcd1f7096eef54f3b9432e2f6fa0f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page