From 342c8dc87aa227fb1c68ffa73f91b491d498ec1b Mon Sep 17 00:00:00 2001 From: Anton Roslund Date: Tue, 15 Apr 2025 17:27:15 +0200 Subject: [PATCH] collect ok-to-mqtt falg --- .../20250328205405_add_ok_to_mqtt_to_node/migration.sql | 2 ++ prisma/schema.prisma | 2 ++ src/mqtt.js | 8 ++++++++ 3 files changed, 12 insertions(+) create mode 100644 prisma/migrations/20250328205405_add_ok_to_mqtt_to_node/migration.sql diff --git a/prisma/migrations/20250328205405_add_ok_to_mqtt_to_node/migration.sql b/prisma/migrations/20250328205405_add_ok_to_mqtt_to_node/migration.sql new file mode 100644 index 0000000..9bd381c --- /dev/null +++ b/prisma/migrations/20250328205405_add_ok_to_mqtt_to_node/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `nodes` ADD COLUMN `ok_to_mqtt` BOOLEAN NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6741657..a4d10d6 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -51,6 +51,8 @@ model Node { // this column tracks when an mqtt gateway node uplinked a packet mqtt_connection_state_updated_at DateTime? + ok_to_mqtt Boolean? + created_at DateTime @default(now()) updated_at DateTime @default(now()) @updatedAt diff --git a/src/mqtt.js b/src/mqtt.js index d96b97d..702f240 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -914,6 +914,7 @@ client.on("message", async (topic, message) => { else if(portnum === 4) { const user = User.decode(envelope.packet.decoded.payload); + let isOkToMqtt = null if(logKnownPacketTypes) { console.log("NODEINFO_APP", { @@ -922,6 +923,11 @@ client.on("message", async (topic, message) => { }); } + // check if bitfield is available, then check if ok-to-mqtt + if(bitfield != null){ + isOkToMqtt = Boolean(bitfield & BITFIELD_OK_TO_MQTT_MASK); + } + // create or update node in db try { await prisma.node.upsert({ @@ -936,6 +942,7 @@ client.on("message", async (topic, message) => { is_licensed: user.isLicensed === true, role: user.role, firmware_version: bitfield ? '2.5.0 or newer' : '2.4.3 or older', + ok_to_mqtt: isOkToMqtt, }, update: { long_name: user.longName, @@ -944,6 +951,7 @@ client.on("message", async (topic, message) => { is_licensed: user.isLicensed === true, role: user.role, firmware_version: bitfield ? '2.5.0 or newer' : '2.4.3 or older', + ok_to_mqtt: isOkToMqtt, }, }); } catch (e) {