nodes should be created and updated from map report packets
This commit is contained in:
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE `nodes` MODIFY `is_licensed` BOOLEAN NULL;
|
@ -14,13 +14,13 @@ datasource db {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Node {
|
model Node {
|
||||||
id BigInt @id @default(autoincrement())
|
id BigInt @id @default(autoincrement())
|
||||||
node_id BigInt @unique
|
node_id BigInt @unique
|
||||||
long_name String
|
long_name String
|
||||||
short_name String
|
short_name String
|
||||||
hardware_model Int
|
hardware_model Int
|
||||||
is_licensed Boolean
|
|
||||||
role Int
|
role Int
|
||||||
|
is_licensed Boolean?
|
||||||
|
|
||||||
latitude Int?
|
latitude Int?
|
||||||
longitude Int?
|
longitude Int?
|
||||||
|
36
src/mqtt.js
36
src/mqtt.js
@ -603,10 +603,6 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
else if(portnum === 73) {
|
else if(portnum === 73) {
|
||||||
|
|
||||||
if(!collectMapReports){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapReport = MapReport.decode(envelope.packet.decoded.payload);
|
const mapReport = MapReport.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
if(logKnownPacketTypes) {
|
if(logKnownPacketTypes) {
|
||||||
@ -616,6 +612,38 @@ client.on("message", async (topic, message) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create or update node in db
|
||||||
|
try {
|
||||||
|
|
||||||
|
// data to set on node
|
||||||
|
const data = {
|
||||||
|
long_name: mapReport.longName,
|
||||||
|
short_name: mapReport.shortName,
|
||||||
|
hardware_model: mapReport.hwModel,
|
||||||
|
role: mapReport.role,
|
||||||
|
latitude: mapReport.latitudeI,
|
||||||
|
longitude: mapReport.longitudeI,
|
||||||
|
altitude: mapReport.altitude !== 0 ? mapReport.altitude : null,
|
||||||
|
};
|
||||||
|
|
||||||
|
await prisma.node.upsert({
|
||||||
|
where: {
|
||||||
|
node_id: envelope.packet.from,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
node_id: envelope.packet.from,
|
||||||
|
...data,
|
||||||
|
},
|
||||||
|
update: data,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!collectMapReports){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// find an existing map with duplicate information created in the last 60 seconds
|
// find an existing map with duplicate information created in the last 60 seconds
|
||||||
|
Reference in New Issue
Block a user