collect device metrics telemetry
This commit is contained in:
@ -0,0 +1,5 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `nodes` ADD COLUMN `air_util_tx` DECIMAL(65, 30) NULL,
|
||||||
|
ADD COLUMN `battery_level` INTEGER NULL,
|
||||||
|
ADD COLUMN `channel_utilization` DECIMAL(65, 30) NULL,
|
||||||
|
ADD COLUMN `voltage` DECIMAL(65, 30) NULL;
|
@ -26,6 +26,11 @@ model Node {
|
|||||||
longitude Int?
|
longitude Int?
|
||||||
altitude Int?
|
altitude Int?
|
||||||
|
|
||||||
|
battery_level Int?
|
||||||
|
voltage Decimal?
|
||||||
|
channel_utilization Decimal?
|
||||||
|
air_util_tx Decimal?
|
||||||
|
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @default(now()) @updatedAt
|
updated_at DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
|
37
src/mqtt.js
37
src/mqtt.js
@ -20,6 +20,7 @@ root.loadSync('meshtastic/mqtt.proto');
|
|||||||
const Data = root.lookupType("Data");
|
const Data = root.lookupType("Data");
|
||||||
const ServiceEnvelope = root.lookupType("ServiceEnvelope");
|
const ServiceEnvelope = root.lookupType("ServiceEnvelope");
|
||||||
const Position = root.lookupType("Position");
|
const Position = root.lookupType("Position");
|
||||||
|
const Telemetry = root.lookupType("Telemetry");
|
||||||
const User = root.lookupType("User");
|
const User = root.lookupType("User");
|
||||||
|
|
||||||
function createNonce(packetId, fromNode) {
|
function createNonce(packetId, fromNode) {
|
||||||
@ -159,6 +160,42 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(portnum === 67) {
|
||||||
|
|
||||||
|
const telemetry = Telemetry.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
|
console.log("TELEMETRY_APP", {
|
||||||
|
from: envelope.packet.from.toString(16),
|
||||||
|
telemetry: telemetry,
|
||||||
|
});
|
||||||
|
|
||||||
|
// data to update
|
||||||
|
const data = {};
|
||||||
|
|
||||||
|
// handle device metrics
|
||||||
|
if(telemetry.deviceMetrics){
|
||||||
|
data.battery_level = telemetry.deviceMetrics.batteryLevel !== 0 ? telemetry.deviceMetrics.batteryLevel : null;
|
||||||
|
data.voltage = telemetry.deviceMetrics.voltage !== 0 ? telemetry.deviceMetrics.voltage : null;
|
||||||
|
data.channel_utilization = telemetry.deviceMetrics.channelUtilization !== 0 ? telemetry.deviceMetrics.channelUtilization : null;
|
||||||
|
data.air_util_tx = telemetry.deviceMetrics.airUtilTx !== 0 ? telemetry.deviceMetrics.airUtilTx : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update node telemetry in db
|
||||||
|
if(Object.keys(data).length > 0){
|
||||||
|
try {
|
||||||
|
await prisma.node.updateMany({
|
||||||
|
where: {
|
||||||
|
node_id: envelope.packet.from,
|
||||||
|
},
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// ignore errors
|
// ignore errors
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user