From b35b83327714b05ff1a578370b83faeda374ecdb Mon Sep 17 00:00:00 2001 From: bee-mois Date: Sat, 20 Apr 2024 21:28:21 +0200 Subject: [PATCH 01/11] Typo corrected in Acknowledgments section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4b1546..9703f93 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ On our community forum, you can find relevant discussions about this topic. ## Acknowledgements -The original code this implementation has been derived from has been discovered +The original code of this implementation has been discovered on the element14 community forum at [Multiple DS18B20 Temp sensors interfacing with Raspberry Pi], shared by [@laluha]. Thanks! From 3015df093eff2548cd8dbaa5f08bce7bd8304cb5 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:00:44 +0200 Subject: [PATCH 02/11] Chore: Update backlog --- docs/backlog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/backlog.md b/docs/backlog.md index 143e9b8..216df9b 100644 --- a/docs/backlog.md +++ b/docs/backlog.md @@ -1,8 +1,10 @@ # Backlog for ds18b20-datalogger ## Iteration +1 -- Documentation: How to set up Kotori DAQ +- Documentation: MQTT publishing guide - Documentation: How to provision Grafana Dashboard +- Documentation: How to set up Kotori DAQ +- Documentation: Better describe the 5x6 temperature sensor matrix ## Iteration +2 - By default, probe configuration at `/etc/ds18b20-datalogger/config.yaml` From d3d402874900ef5c2406aa4f49ff94fd86fb0b19 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:01:53 +0200 Subject: [PATCH 03/11] Grafana Dashboard: Trim identifying information: id, uid, version --- CHANGES.md | 2 ++ ds18b20_datalogger/grafana-dashboard.json | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a0b1be3..91153d4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changes for ds18b20-datalogger ## Unreleased +- Grafana Dashboard: Trim identifying information: `id`, `uid`, + `version`. Thanks, @bee-mois. ## v0.0.3 - 2024-04-20 - Tests: Make sensor tests work, using a fake sysfs filesystem diff --git a/ds18b20_datalogger/grafana-dashboard.json b/ds18b20_datalogger/grafana-dashboard.json index 0d12c2c..c3373e3 100644 --- a/ds18b20_datalogger/grafana-dashboard.json +++ b/ds18b20_datalogger/grafana-dashboard.json @@ -27,7 +27,6 @@ "editable": true, "gnetId": null, "graphTooltip": 0, - "id": 924, "links": [ { "icon": "external link", @@ -2035,9 +2034,7 @@ }, "timezone": "browser", "title": "DS18B20 Temperature Matrix Heatmap 5x6", - "uid": "T49wHSaIk", "variables": { "list": [] - }, - "version": 7 + } } From 0540592003391be72df83083423f86d5bab318d1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:03:01 +0200 Subject: [PATCH 04/11] Grafana Dashboard: Update tags, using keywords from `pyproject.toml` --- ds18b20_datalogger/grafana-dashboard.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ds18b20_datalogger/grafana-dashboard.json b/ds18b20_datalogger/grafana-dashboard.json index c3373e3..7e059a4 100644 --- a/ds18b20_datalogger/grafana-dashboard.json +++ b/ds18b20_datalogger/grafana-dashboard.json @@ -1993,9 +1993,14 @@ "schemaVersion": 22, "style": "dark", "tags": [ - "instant", - "hiveeyes", - "mois" + "beehive monitoring", + "ds18b20", + "grafana", + "kotori daq", + "mqtt", + "raspberry pi", + "sensor network", + "temperature matrix" ], "templating": { "list": [] From f564d5f241715755c3821085a759fe9dd4207847 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:13:19 +0200 Subject: [PATCH 05/11] Emit user admonition on `make-config` subcommand --- CHANGES.md | 2 ++ ds18b20_datalogger/cli.py | 4 ++++ ds18b20_datalogger/util.py | 7 +++++++ tests/test_cli.py | 6 ++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 91153d4..6845bf7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,8 @@ ## Unreleased - Grafana Dashboard: Trim identifying information: `id`, `uid`, `version`. Thanks, @bee-mois. +- Emit user admonition on `make-config` subcommand. Thanks, + @bee-mois. ## v0.0.3 - 2024-04-20 - Tests: Make sensor tests work, using a fake sysfs filesystem diff --git a/ds18b20_datalogger/cli.py b/ds18b20_datalogger/cli.py index 9976edd..dc6da42 100644 --- a/ds18b20_datalogger/cli.py +++ b/ds18b20_datalogger/cli.py @@ -4,6 +4,7 @@ from ds18b20_datalogger.core import read_ds18b20_sensor_matrix, send_measurement_mqtt from ds18b20_datalogger.model import Settings +from ds18b20_datalogger.util import msg if sys.version_info < (3, 9): from importlib_resources import files # pragma: nocover @@ -33,6 +34,9 @@ def main(): send_measurement_mqtt(settings.mqtt, reading) elif subcommand == "make-config": + print( # noqa: T201 + msg("Please make sure to edit the configuration file before starting the program."), file=sys.stderr + ) config_template = files("ds18b20_datalogger") / "datalogger.yaml" print(config_template.read_text(), file=sys.stdout) # noqa: T201 diff --git a/ds18b20_datalogger/util.py b/ds18b20_datalogger/util.py index 64d5c3f..e39c3a1 100644 --- a/ds18b20_datalogger/util.py +++ b/ds18b20_datalogger/util.py @@ -11,3 +11,10 @@ def partition(lst, chunksize: int) -> Generator[List[Any], None, None]: """ for i in range(0, len(lst), chunksize): yield list(itertools.islice(lst, i, i + chunksize)) + + +def msg(text: str): + """ + Return a text armoured with ANSI codes to make it appear in bright yellow. + """ + return f"\033[1;33m{text}\033[0m" diff --git a/tests/test_cli.py b/tests/test_cli.py index ef2256c..bce15ff 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -49,10 +49,12 @@ def test_cli_run_almost_success(): def test_cli_make_config(): - exitcode, output = invoke("ds18b20-datalogger make-config") - config = yaml.safe_load(output) + command = shlex.split("ds18b20-datalogger make-config") + process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # noqa: S603 + config = yaml.safe_load(process.stdout) assert "mqtt" in config assert "one-wire" in config + assert b"Please make sure to edit the configuration" in process.stderr def test_cli_make_dashboard(): From b9cc32d8a1ba845be330a3fa6b39188b19569ec6 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:29:46 +0200 Subject: [PATCH 06/11] Data Model: Make MQTT settings optional To allow running the data logger without configuring them. --- CHANGES.md | 2 ++ ds18b20_datalogger/model.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6845bf7..ecd343f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ `version`. Thanks, @bee-mois. - Emit user admonition on `make-config` subcommand. Thanks, @bee-mois. +- Data Model: Make MQTT settings optional, to allow running the + data logger without configuring them. ## v0.0.3 - 2024-04-20 - Tests: Make sensor tests work, using a fake sysfs filesystem diff --git a/ds18b20_datalogger/model.py b/ds18b20_datalogger/model.py index db5f4a5..f3e89a1 100644 --- a/ds18b20_datalogger/model.py +++ b/ds18b20_datalogger/model.py @@ -66,8 +66,8 @@ class Settings: General settings container. """ - mqtt: MqttSettings - devicemap: DeviceMap + mqtt: t.Union[MqttSettings, None] + devicemap: t.Union[DeviceMap, None] @classmethod def from_file(cls, configfile: Path): @@ -75,7 +75,10 @@ def from_file(cls, configfile: Path): devicemap = DeviceMap() for item in data["one-wire"]: devicemap.devices.append(Device(**item)) - return cls(mqtt=MqttSettings(**data["mqtt"]), devicemap=devicemap) + mqtt = None + if "mqtt" in data: + mqtt = MqttSettings(**data["mqtt"]) + return cls(mqtt=mqtt, devicemap=devicemap) @dataclasses.dataclass From 55881e7523aacb85f7386216da120e2e7a459d7f Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:35:02 +0200 Subject: [PATCH 07/11] Allow defining per-sensor offsets within the configuration file --- CHANGES.md | 2 ++ ds18b20_datalogger/core.py | 2 ++ ds18b20_datalogger/datalogger.yaml | 6 ++++++ ds18b20_datalogger/model.py | 1 + tests/datalogger-offset.yaml | 11 +++++++++++ tests/test_core.py | 15 +++++++++++++++ 6 files changed, 37 insertions(+) create mode 100644 tests/datalogger-offset.yaml diff --git a/CHANGES.md b/CHANGES.md index ecd343f..86137cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ @bee-mois. - Data Model: Make MQTT settings optional, to allow running the data logger without configuring them. +- Allow defining per-sensor offsets within the configuration + file. Thanks, @bee-mois. ## v0.0.3 - 2024-04-20 - Tests: Make sensor tests work, using a fake sysfs filesystem diff --git a/ds18b20_datalogger/core.py b/ds18b20_datalogger/core.py index a5ee853..a8db447 100755 --- a/ds18b20_datalogger/core.py +++ b/ds18b20_datalogger/core.py @@ -73,5 +73,7 @@ def read_ds18b20_sensor_matrix(devicemap: DeviceMap) -> Reading: reading = Reading() for device in devicemap.devices: value = read_temp(device.path) + if value is not None and device.offset is not None: + value += device.offset reading.add_measurement(name=device.name, value=value) return reading diff --git a/ds18b20_datalogger/datalogger.yaml b/ds18b20_datalogger/datalogger.yaml index bcb70a5..ae6f3be 100644 --- a/ds18b20_datalogger/datalogger.yaml +++ b/ds18b20_datalogger/datalogger.yaml @@ -19,13 +19,19 @@ mqtt: one-wire: - name: temp-ir-1-1 path: /sys/bus/w1/devices/28-0346d4430b06 + offset: null - name: temp-ir-1-2 path: /sys/bus/w1/devices/28-0cf3d443ba40 + offset: null - name: temp-ir-1-3 path: /sys/bus/w1/devices/28-0e49d44343bd + offset: null - name: temp-ir-2-1 path: /sys/bus/w1/devices/28-2231d443d266 + offset: null - name: temp-ir-2-2 path: /sys/bus/w1/devices/28-282bd4430f5e + offset: null - name: temp-ir-2-3 path: /sys/bus/w1/devices/28-2846d443e4f2 + offset: null diff --git a/ds18b20_datalogger/model.py b/ds18b20_datalogger/model.py index f3e89a1..b495e92 100644 --- a/ds18b20_datalogger/model.py +++ b/ds18b20_datalogger/model.py @@ -16,6 +16,7 @@ class Device: name: str path: str + offset: t.Union[float, None] = None class DeviceMap: diff --git a/tests/datalogger-offset.yaml b/tests/datalogger-offset.yaml new file mode 100644 index 0000000..e1289f4 --- /dev/null +++ b/tests/datalogger-offset.yaml @@ -0,0 +1,11 @@ +# Test configuration file for validating per-sensor offsets. + +one-wire: + - name: temp-ir-1-1 + path: /sys/bus/w1/devices/28-0346d4430b06 + offset: -0.5 + - name: temp-ir-1-2 + path: /sys/bus/w1/devices/28-0cf3d443ba40 + offset: null + - name: temp-ir-1-3 + path: /sys/bus/w1/devices/28-0e49d44343bd diff --git a/tests/test_core.py b/tests/test_core.py index 578f9e7..f632a9f 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -109,3 +109,18 @@ def test_sensors_none(settings): def test_telemetry(settings): reading = read_ds18b20_sensor_matrix(settings.devicemap) send_measurement_mqtt(settings.mqtt, reading) + + +@pytest.fixture +def offset_settings() -> Settings: + configfile = Path("tests") / "datalogger-offset.yaml" + return Settings.from_file(configfile) + + +def test_sensors_offset(offset_settings, fake_hardware_success): + reading = read_ds18b20_sensor_matrix(offset_settings.devicemap) + assert reading.to_dict() == { + "temp-ir-1-1": -0.499, + "temp-ir-1-2": 0.002, + "temp-ir-1-3": 0.003, + } From faca3eea306f96d6f49fc870f0fd4f872523e72f Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 22:37:50 +0200 Subject: [PATCH 08/11] Release v0.0.4 --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 86137cf..a995368 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changes for ds18b20-datalogger ## Unreleased + +## v0.0.4 - 2024-04-21 - Grafana Dashboard: Trim identifying information: `id`, `uid`, `version`. Thanks, @bee-mois. - Emit user admonition on `make-config` subcommand. Thanks, From 70742b735202388d651732b7d345462dab558ecb Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 21 Apr 2024 23:05:25 +0200 Subject: [PATCH 09/11] Fix documentation about production use: Missing statement about `mkdir` --- docs/production.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/production.md b/docs/production.md index b2ff351..590c85a 100644 --- a/docs/production.md +++ b/docs/production.md @@ -7,6 +7,7 @@ document. ## Installation ```shell sudo su - +mkdir -p /etc/ds18b20-datalogger python3 -m venv /opt/ds18b20-datalogger /opt/ds18b20-datalogger/bin/pip install ds18b20-datalogger /opt/ds18b20-datalogger/bin/ds18b20-datalogger make-config > /etc/ds18b20-datalogger/config.yaml From 7dc8e7ed1fc4bda783ada6c30f916ac0aaece092 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 19:22:39 +0000 Subject: [PATCH 10/11] Update ruff requirement from <0.4 to <0.5 Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/v0.0.18...v0.4.1) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a82c734..d174d86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ develop = [ "mypy<1.10", "poethepoet<0.26", "pyproject-fmt<1.8", - "ruff<0.4", + "ruff<0.5", "validate-pyproject<0.17", ] docs = [ From d1a22d944908197169cac0b5c70b7047965a1a53 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:24:03 +0000 Subject: [PATCH 11/11] Update pyproject-fmt requirement from <1.8 to <1.9 Updates the requirements on [pyproject-fmt](https://github.com/tox-dev/pyproject-fmt) to permit the latest version. - [Release notes](https://github.com/tox-dev/pyproject-fmt/releases) - [Commits](https://github.com/tox-dev/pyproject-fmt/compare/0.1.0...1.8.0) --- updated-dependencies: - dependency-name: pyproject-fmt dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d174d86..22812c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ develop = [ "black<25", "mypy<1.10", "poethepoet<0.26", - "pyproject-fmt<1.8", + "pyproject-fmt<1.9", "ruff<0.5", "validate-pyproject<0.17", ]