Skip to content

Commit

Permalink
update node device metrics when telemetry packets are received
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Dec 5, 2024
1 parent faf2968 commit 0afb757
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0afb757

Please sign in to comment.