diff --git a/CLAUDE.md b/CLAUDE.md index 5fe00c0..8292275 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -73,14 +73,15 @@ The bridge supports configurable event subscriptions: - `CONNECTED`, `DISCONNECTED` (connection status) - `LOGIN_SUCCESS`, `LOGIN_FAILED` (authentication) - `DEVICE_INFO`, `BATTERY`, `NEW_CONTACT` (device info) -- `MESSAGES_WAITING` (notifications) +- `ADVERTISEMENT`, `TRACE_DATA` (network diagnostics) **Additional Events**: -- `ADVERTISEMENT`, `TELEMETRY`, `POSITION` +- `TELEMETRY`, `POSITION` - `ROUTING`, `ADMIN`, `USER` - `TEXT_MESSAGE_RX`, `TEXT_MESSAGE_TX` -- `WAYPOINT`, `NEIGHBOR_INFO`, `TRACEROUTE` +- `WAYPOINT`, `NEIGHBOR_INFO` - `NODE_LIST_CHANGED`, `CONFIG_CHANGED` +- `MESSAGES_WAITING` (notifications) ### Auto-Fetch Restart Feature @@ -130,6 +131,7 @@ The bridge supports bidirectional communication via MQTT commands. Send commands | `set_name` | Set device name | `name` | `meshcore.commands.set_name()` | | `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()` | **Command Examples**: ```json @@ -156,6 +158,12 @@ The bridge supports bidirectional communication via MQTT commands. Send commands // Send advertisement with flood {"flood": true} + +// Send trace packet (basic) +{} + +// Send trace packet with parameters +{"auth_code": 12345, "tag": 67890, "flags": 1, "path": "23,5f,3a"} ``` **Command Examples**: @@ -188,6 +196,13 @@ mosquitto_pub -h localhost -t "meshcore/command/send_advert" -m '{}' # Send device advertisement with flood mosquitto_pub -h localhost -t "meshcore/command/send_advert" \ -m '{"flood": true}' + +# Send trace packet (basic) +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"}' ``` ## Development Guidelines diff --git a/README.md b/README.md index 4f7d531..bd24747 100644 --- a/README.md +++ b/README.md @@ -221,10 +221,11 @@ If no events are specified, the bridge subscribes to these default events: - `DISCONNECTED` - Device disconnection events - `LOGIN_SUCCESS` - Successful authentication - `LOGIN_FAILED` - Failed authentication -- `MESSAGES_WAITING` - Pending messages notification - `DEVICE_INFO` - Device information updates - `BATTERY` - Battery status updates - `NEW_CONTACT` - New contact discovered +- `ADVERTISEMENT` - Device advertisement broadcasts +- `TRACE_DATA` - Network trace information ### Additional Supported Events You can also subscribe to these additional event types: @@ -237,10 +238,9 @@ You can also subscribe to these additional event types: - `TEXT_MESSAGE_TX` - Text messages transmitted - `WAYPOINT` - Waypoint data - `NEIGHBOR_INFO` - Neighbor node information -- `TRACEROUTE` - Network trace information - `NODE_LIST_CHANGED` - Node list updates - `CONFIG_CHANGED` - Configuration changes -- `ADVERTISEMENT` - Device advertisement broadcasts +- `MESSAGES_WAITING` - Pending messages notification ### Configuration Examples @@ -341,6 +341,14 @@ Send commands to MeshCore devices via MQTT using `{prefix}/command/{command_type ```json {"destination": "node_id"} ``` +- `{prefix}/command/send_trace` - Send trace packet for routing diagnostics + ```json + // Basic trace + {} + + // Trace with specific routing path through repeaters + {"auth_code": 12345, "path": "23,5f,3a", "flags": 1} + ``` ### MQTT Command Examples @@ -372,6 +380,13 @@ mosquitto_pub -h localhost -t "meshcore/command/send_advert" -m '{}' # Send device advertisement with flood mosquitto_pub -h localhost -t "meshcore/command/send_advert" \ -m '{"flood": true}' + +# Send trace packet (basic routing diagnostics) +mosquitto_pub -h localhost -t "meshcore/command/send_trace" -m '{}' + +# 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"}' ``` ### Available MeshCore Commands @@ -387,6 +402,7 @@ The bridge supports these MeshCore commands via MQTT: | `set_name` | Set device name | `name` | `{"name": "MyDevice"}` | | `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"}` | ### Topic Examples - `meshcore/message/channel/0` - Channel 0 messages @@ -396,8 +412,10 @@ The bridge supports these MeshCore commands via MQTT: - `meshcore/battery` - Battery level updates - `meshcore/device_info` - Device specifications and capabilities - `meshcore/advertisement` - Device advertisement broadcasts +- `meshcore/traceroute` - Network trace responses - `meshcore/command/send_msg` - Send message command (subscribed) - `meshcore/command/ping` - Ping command (subscribed) +- `meshcore/command/send_trace` - Send trace packet command (subscribed) ## Docker Deployment diff --git a/meshcore_mqtt/config.py b/meshcore_mqtt/config.py index 4d3e829..1fcc80a 100644 --- a/meshcore_mqtt/config.py +++ b/meshcore_mqtt/config.py @@ -91,6 +91,7 @@ class MeshCoreConfig(BaseModel): "BATTERY", "NEW_CONTACT", "ADVERTISEMENT", + "TRACE_DATA", ], description="List of MeshCore event types to subscribe to", ) @@ -142,6 +143,7 @@ class MeshCoreConfig(BaseModel): "WAYPOINT", "NEIGHBOR_INFO", "TRACEROUTE", + "TRACE_DATA", "ADVERTISEMENT", } diff --git a/meshcore_mqtt/meshcore_worker.py b/meshcore_mqtt/meshcore_worker.py index c65c3a4..41e80fc 100644 --- a/meshcore_mqtt/meshcore_worker.py +++ b/meshcore_mqtt/meshcore_worker.py @@ -334,6 +334,15 @@ class MeshCoreWorker: flood = command_data.get("flood", False) result = await self.meshcore.commands.send_advert(flood=flood) + elif command_type == "send_trace": + auth_code = command_data.get("auth_code", 0) + tag = command_data.get("tag") # Optional, will be auto-generated + flags = command_data.get("flags", 0) + path = command_data.get("path") # Optional path specification + result = await self.meshcore.commands.send_trace( + auth_code=auth_code, tag=tag, flags=flags, path=path + ) + else: self.logger.warning(f"Unknown command type: {command_type}") return diff --git a/meshcore_mqtt/mqtt_worker.py b/meshcore_mqtt/mqtt_worker.py index 67c1a0c..06b0e34 100644 --- a/meshcore_mqtt/mqtt_worker.py +++ b/meshcore_mqtt/mqtt_worker.py @@ -372,6 +372,8 @@ class MQTTWorker: return f"{self.config.mqtt.topic_prefix}/new_contact" elif event_name == "ADVERTISEMENT": return f"{self.config.mqtt.topic_prefix}/advertisement" + elif event_name == "TRACE_DATA": + return f"{self.config.mqtt.topic_prefix}/traceroute" # Fallback for unknown event types return f"{self.config.mqtt.topic_prefix}/event" diff --git a/tests/test_configurable_events.py b/tests/test_configurable_events.py index 3a16732..262beba 100644 --- a/tests/test_configurable_events.py +++ b/tests/test_configurable_events.py @@ -31,6 +31,7 @@ class TestConfigurableEvents: "BATTERY", "NEW_CONTACT", "ADVERTISEMENT", + "TRACE_DATA", ] assert config.events == expected_events @@ -223,6 +224,7 @@ class TestConfigurableEvents: "BATTERY", "NEW_CONTACT", "ADVERTISEMENT", + "TRACE_DATA", ] assert config.meshcore.events == expected_events