From 0afb7577a15c45bdb572fa4ed96d778f78bf11f7 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Thu, 5 Dec 2024 20:12:08 +1300 Subject: [PATCH] update node device metrics when telemetry packets are received --- src/js/Connection.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/js/Connection.js b/src/js/Connection.js index 5c4a158..d8c98e9 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -375,6 +375,27 @@ class Connection { } }); + // listen for telemetry + connection.events.onTelemetryPacket.subscribe(async (telemetryPacket) => { + + await databaseToBeReady; + console.log("onTelemetryPacket", telemetryPacket); + + // find node this telemetry is from, otherwise do nothing + const from = telemetryPacket.from; + const node = GlobalState.nodesById[from]; + if(!node){ + return; + } + + // update device metrics for node + if(telemetryPacket.data.variant.case === "deviceMetrics"){ + const deviceMetrics = telemetryPacket.data.variant.value; + node.deviceMetrics = deviceMetrics; + } + + }); + } static async onPacketAck(requestId, ackedByNodeId, hopsAway) {