From 31c727cab03f434afade1e48b87bd55d643fe265 Mon Sep 17 00:00:00 2001 From: Louis King Date: Tue, 19 Aug 2025 23:06:23 +0100 Subject: [PATCH] feat: add telemetry request command and move SELF_INFO to optional events --- CLAUDE.md | 9 +++++++-- README.md | 7 ++++++- meshcore_mqtt/config.py | 1 - meshcore_mqtt/meshcore_worker.py | 7 +++++++ tests/test_configurable_events.py | 2 -- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c85fba5..7ffa726 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -72,13 +72,13 @@ The bridge supports configurable event subscriptions: - `CONTACT_MSG_RECV`, `CHANNEL_MSG_RECV` (messages) - `DEVICE_INFO`, `BATTERY`, `NEW_CONTACT` (device info) - `ADVERTISEMENT`, `TRACE_DATA` (network diagnostics) -- `TELEMETRY_RESPONSE`, `SELF_INFO`, `CHANNEL_INFO` (device details) +- `TELEMETRY_RESPONSE`, `CHANNEL_INFO` (device details) **Additional Events**: - `CONNECTED`, `DISCONNECTED` (connection status, can be noisy) - `LOGIN_SUCCESS`, `LOGIN_FAILED` (authentication) - `MESSAGES_WAITING` (notifications) -- `CONTACTS` (contact list updates) +- `CONTACTS`, `SELF_INFO` (contact and device information) ### Auto-Fetch Restart Feature @@ -129,6 +129,7 @@ The bridge supports bidirectional communication via MQTT commands. Send commands | `ping` | Ping a node | `destination` | `meshcore.commands.ping()` | | `send_advert` | Send device advertisement | None (optional: `flood`) | `meshcore.commands.send_advert()` | | `send_trace` | Send trace packet for routing diagnostics | None (optional: `auth_code`, `tag`, `flags`, `path`) | `meshcore.commands.send_trace()` | +| `send_telemetry_req` | Request telemetry data from a node | `destination` | `meshcore.commands.send_telemetry_req()` | **Command Examples**: ```json @@ -200,6 +201,10 @@ mosquitto_pub -h localhost -t "meshcore/command/send_trace" -m '{}' # Send trace packet with routing path mosquitto_pub -h localhost -t "meshcore/command/send_trace" \ -m '{"auth_code": 12345, "path": "23,5f,3a"}' + +# Request telemetry data from a node +mosquitto_pub -h localhost -t "meshcore/command/send_telemetry_req" \ + -m '{"destination": "node123"}' ``` ## Development Guidelines diff --git a/README.md b/README.md index d1c68a4..e7dd2b0 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,6 @@ If no events are specified, the bridge subscribes to these default events: - `ADVERTISEMENT` - Device advertisement broadcasts - `TRACE_DATA` - Network trace information - `TELEMETRY_RESPONSE` - Telemetry data responses -- `SELF_INFO` - Own device information - `CHANNEL_INFO` - Channel configuration details ### Additional Supported Events @@ -234,6 +233,7 @@ You can also subscribe to these additional event types: - `LOGIN_FAILED` - Failed authentication - `MESSAGES_WAITING` - Pending messages notification - `CONTACTS` - Contact list updates +- `SELF_INFO` - Own device information ### Configuration Examples @@ -384,6 +384,10 @@ mosquitto_pub -h localhost -t "meshcore/command/send_advert" \ # Send trace packet (basic routing diagnostics) mosquitto_pub -h localhost -t "meshcore/command/send_trace" -m '{}' +# Request telemetry data from a node +mosquitto_pub -h localhost -t "meshcore/command/send_telemetry_req" \ + -m '{"destination": "node123"}' + # Send trace packet with routing path through specific repeaters mosquitto_pub -h localhost -t "meshcore/command/send_trace" \ -m '{"auth_code": 12345, "path": "23,5f,3a"}' @@ -413,6 +417,7 @@ The bridge supports these MeshCore commands via MQTT: | `ping` | Ping a node | `destination` | `{"destination": "node123"}` | | `send_advert` | Send device advertisement | None (optional: `flood`) | `{}` or `{"flood": true}` | | `send_trace` | Send trace packet for routing diagnostics | None (optional: `auth_code`, `tag`, `flags`, `path`) | `{}` or `{"auth_code": 12345, "path": "23,5f,3a"}` | +| `send_telemetry_req` | Request telemetry data from a node | `destination` | `{"destination": "node123"}` | ### Topic Examples - `meshcore/message/channel/0` - Channel 0 messages diff --git a/meshcore_mqtt/config.py b/meshcore_mqtt/config.py index 5af8320..ba1a8cf 100644 --- a/meshcore_mqtt/config.py +++ b/meshcore_mqtt/config.py @@ -89,7 +89,6 @@ class MeshCoreConfig(BaseModel): "ADVERTISEMENT", "TRACE_DATA", "TELEMETRY_RESPONSE", - "SELF_INFO", "CHANNEL_INFO", ], description="List of MeshCore event types to subscribe to", diff --git a/meshcore_mqtt/meshcore_worker.py b/meshcore_mqtt/meshcore_worker.py index 41e80fc..d727da3 100644 --- a/meshcore_mqtt/meshcore_worker.py +++ b/meshcore_mqtt/meshcore_worker.py @@ -343,6 +343,13 @@ class MeshCoreWorker: auth_code=auth_code, tag=tag, flags=flags, path=path ) + elif command_type == "send_telemetry_req": + destination = command_data.get("destination") + if not destination: + self.logger.error("send_telemetry_req requires 'destination' field") + return + result = await self.meshcore.commands.send_telemetry_req(destination) + else: self.logger.warning(f"Unknown command type: {command_type}") return diff --git a/tests/test_configurable_events.py b/tests/test_configurable_events.py index 29d2fdf..18f2ffa 100644 --- a/tests/test_configurable_events.py +++ b/tests/test_configurable_events.py @@ -29,7 +29,6 @@ class TestConfigurableEvents: "ADVERTISEMENT", "TRACE_DATA", "TELEMETRY_RESPONSE", - "SELF_INFO", "CHANNEL_INFO", ] @@ -214,7 +213,6 @@ class TestConfigurableEvents: "ADVERTISEMENT", "TRACE_DATA", "TELEMETRY_RESPONSE", - "SELF_INFO", "CHANNEL_INFO", ] assert config.meshcore.events == expected_events