diff --git a/prisma/migrations/20240323095120_add_neighbour_info_columns_to_nodes_table/migration.sql b/prisma/migrations/20240323095120_add_neighbour_info_columns_to_nodes_table/migration.sql new file mode 100644 index 0000000..f63c1e7 --- /dev/null +++ b/prisma/migrations/20240323095120_add_neighbour_info_columns_to_nodes_table/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE `nodes` ADD COLUMN `neighbour_broadcast_interval_secs` INTEGER NULL, + ADD COLUMN `neighbours` JSON NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3df4362..1e46a53 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -31,6 +31,9 @@ model Node { channel_utilization Decimal? air_util_tx Decimal? + neighbour_broadcast_interval_secs Int? + neighbours Json? + created_at DateTime @default(now()) updated_at DateTime @default(now()) @updatedAt diff --git a/src/mqtt.js b/src/mqtt.js index 6f56320..53a914f 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -273,6 +273,7 @@ client.on("message", async (topic, message) => { }); } + // create neighbour info try { await prisma.neighbourInfo.create({ data: { @@ -290,6 +291,26 @@ client.on("message", async (topic, message) => { console.error(e); } + // update node neighbour info in db + try { + await prisma.node.updateMany({ + where: { + node_id: envelope.packet.from, + }, + data: { + neighbour_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, + neighbours: neighbourInfo.neighbors.map((neighbour) => { + return { + node_id: neighbour.nodeId, + snr: neighbour.snr, + }; + }), + }, + }); + } catch (e) { + console.error(e); + } + } else if(portnum === 67) {