Skip to content

Commit

Permalink
Merge pull request #667 from ianmcorvidae/telemetry-updating
Browse files Browse the repository at this point in the history
Update telemetry in interface.nodes on receiving device metrics packets
  • Loading branch information
ianmcorvidae authored Sep 6, 2024
2 parents 0813e8d + 78d8403 commit 83b0dca
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion meshtastic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ def _onNodeInfoReceive(iface, asDict):
iface.nodes[p["id"]] = n
_receiveInfoUpdate(iface, asDict)

def _onTelemetryReceive(iface, asDict):
"""Automatically update device metrics on received packets"""
logging.debug(f"in _onTelemetryReceive() asDict:{asDict}")
deviceMetrics = asDict.get("decoded", {}).get("telemetry", {}).get("deviceMetrics")
if "from" in asDict and deviceMetrics is not None:
node = iface._getOrCreateByNum(asDict["from"])
newMetrics = node.get("deviceMetrics", {})
newMetrics.update(deviceMetrics)
logging.debug(f"updating metrics for {asDict['from']} to {newMetrics}")
node["deviceMetrics"] = newMetrics

def _receiveInfoUpdate(iface, asDict):
if "from" in asDict:
Expand Down Expand Up @@ -221,7 +231,7 @@ def _receiveInfoUpdate(iface, asDict):
portnums_pb2.PortNum.ADMIN_APP: KnownProtocol("admin", admin_pb2.AdminMessage),
portnums_pb2.PortNum.ROUTING_APP: KnownProtocol("routing", mesh_pb2.Routing),
portnums_pb2.PortNum.TELEMETRY_APP: KnownProtocol(
"telemetry", telemetry_pb2.Telemetry
"telemetry", telemetry_pb2.Telemetry, _onTelemetryReceive
),
portnums_pb2.PortNum.REMOTE_HARDWARE_APP: KnownProtocol(
"remotehw", remote_hardware_pb2.HardwareMessage
Expand Down

0 comments on commit 83b0dca

Please sign in to comment.