mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-06-11 00:34:46 +02:00
9bfe1259da
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>