diff --git a/prisma/migrations/20240312222245_create_neighbour_info_table/migration.sql b/prisma/migrations/20240312222245_create_neighbour_info_table/migration.sql new file mode 100644 index 0000000..9df6a3e --- /dev/null +++ b/prisma/migrations/20240312222245_create_neighbour_info_table/migration.sql @@ -0,0 +1,13 @@ +-- CreateTable +CREATE TABLE `neighbour_infos` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `node_id` BIGINT NOT NULL, + `node_broadcast_interval_secs` INTEGER NOT NULL, + `neighbours` JSON NOT NULL, + `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + + INDEX `neighbour_infos_created_at_idx`(`created_at`), + INDEX `neighbour_infos_updated_at_idx`(`updated_at`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0095baa..6a88dfc 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -38,3 +38,17 @@ model Node { @@index(updated_at) @@map("nodes") } + +model NeighbourInfo { + id BigInt @id @default(autoincrement()) + node_id BigInt + node_broadcast_interval_secs Int + neighbours Json + + created_at DateTime @default(now()) + updated_at DateTime @default(now()) @updatedAt + + @@index(created_at) + @@index(updated_at) + @@map("neighbour_infos") +} diff --git a/src/mqtt.js b/src/mqtt.js index 7a33ca4..ee25b92 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -19,6 +19,7 @@ root.resolvePath = (origin, target) => path.join(__dirname, "protos", target); root.loadSync('meshtastic/mqtt.proto'); const Data = root.lookupType("Data"); const ServiceEnvelope = root.lookupType("ServiceEnvelope"); +const NeighborInfo = root.lookupType("NeighborInfo"); const Position = root.lookupType("Position"); const Telemetry = root.lookupType("Telemetry"); const User = root.lookupType("User"); @@ -160,6 +161,35 @@ client.on("message", async (topic, message) => { } + if(portnum === 71) { + + const neighbourInfo = NeighborInfo.decode(envelope.packet.decoded.payload); + + console.log("NEIGHBORINFO_APP", { + from: envelope.packet.from.toString(16), + // envelope: envelope, + neighbour_info: neighbourInfo, + }); + + try { + await prisma.neighbourInfo.create({ + data: { + node_id: envelope.packet.from, + node_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, + neighbours: neighbourInfo.neighbors.map((neighbour) => { + return { + node_id: neighbour.nodeId, + snr: neighbour.snr, + }; + }), + }, + }); + } catch (e) { + console.error(e); + } + + } + if(portnum === 67) { const telemetry = Telemetry.decode(envelope.packet.decoded.payload);