mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-08-08 01:42:49 +02:00
feat: add ENS210 temperature/humidity sensor plug-in
Adds support for the ENS210 relative humidity and temperature sensor as a new plug-in under repeater/sensors/ens210.py. Also adds a commented configuration example to config.yaml.example and a contributor guide at docs/adding_sensors.md explaining how to add further sensor plug-ins. ## Implementation notes ### Why smbus2 instead of an Adafruit/CircuitPython library The ENS210 has no maintained Adafruit CircuitPython driver. The available third-party options are either unmaintained or bring in the full Blinka/CircuitPython hardware-abstraction stack as a dependency. smbus2 is a thin, widely-packaged wrapper around the Linux i2c-dev kernel interface that is already present on Raspberry Pi OS and most Debian-based systems. It has no transitive dependencies and adds no abstraction cost. The ENS210 protocol is simple enough that direct register access is preferable: two writes to start a measurement (REG_SENS_RUN + REG_SENS_START) and two three-byte block reads to retrieve temperature and humidity. The status/validity bit is checked inline rather than relying on a library to surface it. There is no value a higher-level driver would add here. ### Read strategy A fixed post-trigger delay is unreliable — the sensor datasheet quotes ~130 ms typical conversion time but the actual ready time varies. The implementation instead polls the data-valid status bit (bit 1 of the third byte in each register block) every 50 ms for up to read_timeout_seconds (default 1.0 s), breaking as soon as both T and H report valid data. This is the same approach used in the validated reference script. The I2C bus is opened and closed on every read rather than kept open across poll cycles. Keeping a persistent SMBus handle caused subsequent reads to time out, consistent with the Linux i2c-dev file descriptor accumulating state between transactions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -236,6 +236,16 @@ sensors:
|
||||
# max_expected_amps: 2.0
|
||||
# shunt_ohms: 0.1
|
||||
|
||||
# Example ENS210 temperature/humidity sensor (commented out by default)
|
||||
# - type: ens210
|
||||
# name: ambient
|
||||
# enabled: true
|
||||
# auto_install_packages: true
|
||||
# settings:
|
||||
# i2c_address: 67 # 0x43 in decimal (default ENS210 address)
|
||||
# bus_number: 1 # I2C bus number (1 for Raspberry Pi default)
|
||||
# read_timeout_seconds: 1.0 # Max seconds to wait for valid data (polls every 50 ms)
|
||||
|
||||
# Mesh Network Configuration
|
||||
mesh:
|
||||
# Unscoped flood policy - controls whether the repeater allows or denies unscoped flooding
|
||||
|
||||
Reference in New Issue
Block a user