Skip to main content

A standard library for MQTT sensors within a home -> Given the topic and payload, it will create a sensor object. The payload will be inot the format expected by the [mqtt-influxdb](https://github.com/yfredrix/mqtt-influxdb) container.

Project description

mqttsensor

A Python package for sending sensor data over MQTT with message persistence and reconnection support.

Features

  • MQTT client with TLS support
  • Automatic message storage and resend on connection loss
  • Configurable via TOML file
  • Logging with loguru

Installation

pip install .

Configuration

Create a config.toml file in your project directory:

[mqtt]
broker = "localhost"
port = 1883
client_id = "your_client_id"
ca_certs = "ca.pem"
certfile = "cert.pem"
key = "key.pem"
max_times = 3

Usage

from mqttsensor.main import init_client

config, mqtt_client = init_client("config.toml")
mqtt_client.start()
# Send sensor data
mqtt_client.send_sensor_data(
    measurement="temperature",
    location="office",
    sensor_id="sensor01",
    unit="C",
    value=23.5
)
mqtt_client.stop()

Testing

Run all tests with:

pytest

License

MIT License

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

mqttsensor-0.1.1.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

mqttsensor-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file mqttsensor-0.1.1.tar.gz.

File metadata

  • Download URL: mqttsensor-0.1.1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.5

File hashes

Hashes for mqttsensor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 09beabd9d7cc59a267527c6cc16c7d6d288bc72f8fc65d98b6cd2ce7aafc5d25
MD5 c12ef27f577f8cea511c240039252255
BLAKE2b-256 e4deb5f89259419c9e6047b58e5ef7ebc3c16125bdcdd69f3e66c4953ab7768d

See more details on using hashes here.

File details

Details for the file mqttsensor-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mqttsensor-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.5

File hashes

Hashes for mqttsensor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e85c6fd9d142a1a05544cd109ed50b75aac1cd4337cdf4675485edbf35c332d
MD5 2a5608b623186e1d18c3f276b262ffbd
BLAKE2b-256 62a41706ca367067f976e6633d7c504bdb445f3c893c13d80a5781bdf3317503

See more details on using hashes here.

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