mirror of
https://github.com/ipnet-mesh/meshcore-mqtt.git
synced 2026-08-07 17:33:15 +02:00
refactor: clean up event types and update defaults for better device monitoring
This commit is contained in:
@@ -70,18 +70,15 @@ The bridge supports configurable event subscriptions:
|
||||
|
||||
**Default Events**:
|
||||
- `CONTACT_MSG_RECV`, `CHANNEL_MSG_RECV` (messages)
|
||||
- `LOGIN_SUCCESS`, `LOGIN_FAILED` (authentication)
|
||||
- `DEVICE_INFO`, `BATTERY`, `NEW_CONTACT` (device info)
|
||||
- `ADVERTISEMENT`, `TRACE_DATA` (network diagnostics)
|
||||
- `TELEMETRY_RESPONSE`, `SELF_INFO`, `CHANNEL_INFO` (device details)
|
||||
|
||||
**Additional Events**:
|
||||
- `CONNECTED`, `DISCONNECTED` (connection status, can be noisy)
|
||||
- `TELEMETRY`, `POSITION`
|
||||
- `ROUTING`, `ADMIN`, `USER`
|
||||
- `TEXT_MESSAGE_RX`, `TEXT_MESSAGE_TX`
|
||||
- `WAYPOINT`, `NEIGHBOR_INFO`
|
||||
- `NODE_LIST_CHANGED`, `CONFIG_CHANGED`
|
||||
- `LOGIN_SUCCESS`, `LOGIN_FAILED` (authentication)
|
||||
- `MESSAGES_WAITING` (notifications)
|
||||
- `CONTACTS` (contact list updates)
|
||||
|
||||
### Auto-Fetch Restart Feature
|
||||
|
||||
|
||||
@@ -217,30 +217,23 @@ The bridge can subscribe to various MeshCore event types. You can configure whic
|
||||
If no events are specified, the bridge subscribes to these default events:
|
||||
- `CONTACT_MSG_RECV` - Contact messages received
|
||||
- `CHANNEL_MSG_RECV` - Channel messages received
|
||||
- `LOGIN_SUCCESS` - Successful authentication
|
||||
- `LOGIN_FAILED` - Failed authentication
|
||||
- `DEVICE_INFO` - Device information updates
|
||||
- `BATTERY` - Battery status updates
|
||||
- `NEW_CONTACT` - New contact discovered
|
||||
- `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
|
||||
You can also subscribe to these additional event types:
|
||||
- `CONNECTED` - Device connection events (can be noisy)
|
||||
- `DISCONNECTED` - Device disconnection events (can be noisy)
|
||||
- `TELEMETRY` - Telemetry data
|
||||
- `POSITION` - Position/GPS updates
|
||||
- `USER` - User-related events
|
||||
- `ROUTING` - Mesh routing events
|
||||
- `ADMIN` - Administrative messages
|
||||
- `TEXT_MESSAGE_RX` - Text messages received
|
||||
- `TEXT_MESSAGE_TX` - Text messages transmitted
|
||||
- `WAYPOINT` - Waypoint data
|
||||
- `NEIGHBOR_INFO` - Neighbor node information
|
||||
- `NODE_LIST_CHANGED` - Node list updates
|
||||
- `CONFIG_CHANGED` - Configuration changes
|
||||
- `LOGIN_SUCCESS` - Successful authentication
|
||||
- `LOGIN_FAILED` - Failed authentication
|
||||
- `MESSAGES_WAITING` - Pending messages notification
|
||||
- `CONTACTS` - Contact list updates
|
||||
|
||||
### Configuration Examples
|
||||
|
||||
@@ -270,8 +263,6 @@ meshcore:
|
||||
- CHANNEL_MSG_RECV
|
||||
- CONNECTED
|
||||
- DISCONNECTED
|
||||
- TELEMETRY
|
||||
- POSITION
|
||||
- BATTERY
|
||||
- DEVICE_INFO
|
||||
- ADVERTISEMENT
|
||||
@@ -312,6 +303,10 @@ Where:
|
||||
- `{prefix}/battery` - Battery status from BATTERY events
|
||||
- `{prefix}/new_contact` - Contact discovery from NEW_CONTACT events
|
||||
- `{prefix}/advertisement` - Device advertisements from ADVERTISEMENT events
|
||||
- `{prefix}/telemetry` - Telemetry data from TELEMETRY_RESPONSE events
|
||||
- `{prefix}/contacts` - Contact list updates from CONTACTS events
|
||||
- `{prefix}/self_info` - Own device information from SELF_INFO events
|
||||
- `{prefix}/channel_info` - Channel configuration from CHANNEL_INFO events
|
||||
|
||||
### Command Topics (MQTT → MeshCore)
|
||||
Send commands to MeshCore devices via MQTT using `{prefix}/command/{command_type}` with JSON payloads:
|
||||
|
||||
+8
-15
@@ -83,13 +83,14 @@ class MeshCoreConfig(BaseModel):
|
||||
default=[
|
||||
"CONTACT_MSG_RECV",
|
||||
"CHANNEL_MSG_RECV",
|
||||
"LOGIN_SUCCESS",
|
||||
"LOGIN_FAILED",
|
||||
"DEVICE_INFO",
|
||||
"BATTERY",
|
||||
"NEW_CONTACT",
|
||||
"ADVERTISEMENT",
|
||||
"TRACE_DATA",
|
||||
"TELEMETRY_RESPONSE",
|
||||
"SELF_INFO",
|
||||
"CHANNEL_INFO",
|
||||
],
|
||||
description="List of MeshCore event types to subscribe to",
|
||||
)
|
||||
@@ -117,7 +118,7 @@ class MeshCoreConfig(BaseModel):
|
||||
# Normalize to uppercase for case-insensitive validation
|
||||
normalized_events = [event.upper() for event in v]
|
||||
|
||||
# Common MeshCore event types (based on typical mesh networking events)
|
||||
# Valid MeshCore event types (based on actual EventType enum)
|
||||
valid_events = {
|
||||
"CONTACT_MSG_RECV",
|
||||
"CHANNEL_MSG_RECV",
|
||||
@@ -129,20 +130,12 @@ class MeshCoreConfig(BaseModel):
|
||||
"DEVICE_INFO",
|
||||
"BATTERY",
|
||||
"NEW_CONTACT",
|
||||
"NODE_LIST_CHANGED",
|
||||
"CONFIG_CHANGED",
|
||||
"TELEMETRY",
|
||||
"POSITION",
|
||||
"USER",
|
||||
"ROUTING",
|
||||
"ADMIN",
|
||||
"TEXT_MESSAGE_RX",
|
||||
"TEXT_MESSAGE_TX",
|
||||
"WAYPOINT",
|
||||
"NEIGHBOR_INFO",
|
||||
"TRACEROUTE",
|
||||
"TRACE_DATA",
|
||||
"ADVERTISEMENT",
|
||||
"TELEMETRY_RESPONSE",
|
||||
"CONTACTS",
|
||||
"SELF_INFO",
|
||||
"CHANNEL_INFO",
|
||||
}
|
||||
|
||||
invalid_events = [
|
||||
|
||||
@@ -380,6 +380,14 @@ class MQTTWorker:
|
||||
elif hasattr(event_data, "attributes") and event_data.attributes:
|
||||
trace_tag = event_data.attributes.get("tag", "unknown")
|
||||
return f"{self.config.mqtt.topic_prefix}/traceroute/{trace_tag}"
|
||||
elif event_name == "TELEMETRY_RESPONSE":
|
||||
return f"{self.config.mqtt.topic_prefix}/telemetry"
|
||||
elif event_name == "CONTACTS":
|
||||
return f"{self.config.mqtt.topic_prefix}/contacts"
|
||||
elif event_name == "SELF_INFO":
|
||||
return f"{self.config.mqtt.topic_prefix}/self_info"
|
||||
elif event_name == "CHANNEL_INFO":
|
||||
return f"{self.config.mqtt.topic_prefix}/channel_info"
|
||||
|
||||
# Fallback for unknown event types
|
||||
return f"{self.config.mqtt.topic_prefix}/event"
|
||||
|
||||
@@ -23,13 +23,14 @@ class TestConfigurableEvents:
|
||||
expected_events = [
|
||||
"CONTACT_MSG_RECV",
|
||||
"CHANNEL_MSG_RECV",
|
||||
"LOGIN_SUCCESS",
|
||||
"LOGIN_FAILED",
|
||||
"DEVICE_INFO",
|
||||
"BATTERY",
|
||||
"NEW_CONTACT",
|
||||
"ADVERTISEMENT",
|
||||
"TRACE_DATA",
|
||||
"TELEMETRY_RESPONSE",
|
||||
"SELF_INFO",
|
||||
"CHANNEL_INFO",
|
||||
]
|
||||
|
||||
assert config.events == expected_events
|
||||
@@ -58,13 +59,8 @@ class TestConfigurableEvents:
|
||||
"DEVICE_INFO",
|
||||
"BATTERY",
|
||||
"NEW_CONTACT",
|
||||
"NODE_LIST_CHANGED",
|
||||
"CONFIG_CHANGED",
|
||||
"TELEMETRY",
|
||||
"POSITION",
|
||||
"USER",
|
||||
"ROUTING",
|
||||
"ADMIN",
|
||||
"TRACE_DATA",
|
||||
"ADVERTISEMENT",
|
||||
]
|
||||
|
||||
config = MeshCoreConfig(
|
||||
@@ -212,13 +208,14 @@ class TestConfigurableEvents:
|
||||
expected_events = [
|
||||
"CONTACT_MSG_RECV",
|
||||
"CHANNEL_MSG_RECV",
|
||||
"LOGIN_SUCCESS",
|
||||
"LOGIN_FAILED",
|
||||
"DEVICE_INFO",
|
||||
"BATTERY",
|
||||
"NEW_CONTACT",
|
||||
"ADVERTISEMENT",
|
||||
"TRACE_DATA",
|
||||
"TELEMETRY_RESPONSE",
|
||||
"SELF_INFO",
|
||||
"CHANNEL_INFO",
|
||||
]
|
||||
assert config.meshcore.events == expected_events
|
||||
|
||||
|
||||
Reference in New Issue
Block a user