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.2.0.tar.gz (23.3 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.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mqttsensor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5dbce901e4dc4f11e922996c3b33d1264e9b2f1b044d525e290a8a5d79c89aea
MD5 8e797f1acf539a905867531c6f015d4c
BLAKE2b-256 e4e6a362bb4ff8097e297e6e485e804c704922b0a3cab45881e7da9a2af1a06d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mqttsensor-0.2.0-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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76255eb1ee051a683744afc03f5ba072a64fed84884c4aa547bbcbec182205a0
MD5 98942a7b8bcaab8ac58e1c387396407b
BLAKE2b-256 a8027aa75336b05014589534927bf61d686e6acdf6870b84e800fa8c7725dd5b

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