commit 2ae72213be9cb12b370f1f19253dda140bcfbb81 Author: Fiona Grzebien Date: Tue Oct 21 02:35:40 2025 +0200 WIP diff --git a/.gitingnore b/.gitingnore new file mode 100644 index 0000000..f7275bb --- /dev/null +++ b/.gitingnore @@ -0,0 +1 @@ +venv/ diff --git a/main.py b/main.py new file mode 100755 index 0000000..f8fada3 --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import asyncio +import json +from meshcore import MeshCore, EventType +from prometheus_client import CollectorRegistry, Gauge, push_to_gateway + +async def main(): + meshcore = await MeshCore.create_serial("/dev/ttyACM0") + + result = await meshcore.commands.send_telemetry_req("4a629a62e51f0ec770afc47bb22010df0ac1c47475499b6b5e47b3487a4f71e6") + if result.type == EventType.ERROR: + pass + + await meshcore.ensure_contacts() + contact = meshcore.get_contact_by_key_prefix("4a629a62e51f0ec770afc47bb22010df0ac1c47475499b6b5e47b3487a4f71e6") + print(contact) + + result = await meshcore.wait_for_event(EventType.TELEMETRY_RESPONSE, timeout=10.0) + if result is None: + print(json.dumps({"error" : "Timeout waiting for telemetry"})) + else: + print(json.dumps(result.payload, indent=4)) + + registry = CollectorRegistry() + test = Gauge("voltage", "Battery Voltage", registry=registry) + test.set(result.payload["lpp"][0]["value"]) + push_to_gateway("localhost:9091", job="batchA", registry=registry) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..02c28ec --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +bleak==1.1.1 +dbus-fast==2.44.5 +meshcore==2.1.12 +prometheus_client==0.23.1 +pycayennelpp==2.4.0 +pyserial==3.5 +pyserial-asyncio==0.6