From 349e1080b173b73a7b551ff3df9d78cd73035039 Mon Sep 17 00:00:00 2001 From: Tilen Komel Date: Sun, 4 Aug 2024 16:43:19 +0200 Subject: [PATCH 1/4] Colledct positions by default --- src/mqtt.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mqtt.js b/src/mqtt.js index e5808bc..137129e 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -135,11 +135,11 @@ const mqttUsername = options["mqtt-username"] ?? "meshdev"; const mqttPassword = options["mqtt-password"] ?? "large4cats"; const mqttTopic = options["mqtt-topic"] ?? "msh/#"; const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false; -const collectPositions = options["collect-positions"] ?? false; +const collectPositions = options["collect-positions"] ?? true; const collectTextMessages = options["collect-text-messages"] ?? false; const collectWaypoints = options["collect-waypoints"] ?? true; const collectNeighbourInfo = options["collect-neighbour-info"] ?? false; -const collectMapReports = options["collect-map-reports"] ?? false; +const collectMapReports = options["collect-map-reports"] ?? true; const decryptionKeys = options["decryption-keys"] ?? [ "1PG7OiApB1nwvP+rz05pAQ==", // add default "AQ==" decryption key ]; From fc80d771e8321e871543eaa584a3fcda0bd6228e Mon Sep 17 00:00:00 2001 From: Tilen Komel Date: Sun, 4 Aug 2024 16:44:01 +0200 Subject: [PATCH 2/4] Added /position-history api endpint --- src/index.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/index.js b/src/index.js index deefe20..6f8245d 100644 --- a/src/index.js +++ b/src/index.js @@ -428,6 +428,85 @@ app.get('/api/v1/nodes/:nodeId/traceroutes', async (req, res) => { } }); +app.get('/api/v1/nodes/:nodeId/position-history', async (req, res) => { + try { + + const nodeId = parseInt(req.params.nodeId); + const timeFrom = req.query.time_from ? parseInt(req.query.time_from) : new Date().getTime() - 3600 * 1000; + const timeTo = req.query.time_to ? parseInt(req.query.time_to) : new Date().getTime(); + + const node = await prisma.node.findFirst({ + where: { + node_id: nodeId, + }, + }); + + // make sure node exists + if(!node){ + res.status(404).json({ + message: "Not Found", + }); + return; + } + + const positions = await prisma.position.findMany({ + where: { + node_id: nodeId, + created_at: { + gte: new Date(timeFrom), + lte: new Date(timeTo), + }, + } + }); + + const mapReports = await prisma.mapReport.findMany({ + where: { + node_id: nodeId, + created_at: { + gte: new Date(timeFrom), + lte: new Date(timeTo), + }, + } + }); + + const positionHistory = [] + + positions.forEach((position) => { + positionHistory.push({ + node_id: position.node_id, + latitude: position.latitude, + longitude: position.longitude, + altitude: position.altitude, + accuracy: position.accuracy, + time: position.created_at, + }); + }); + + mapReports.forEach((mapReport) => { + positionHistory.push({ + node_id: mapReport.node_id, + latitude: mapReport.latitude, + longitude: mapReport.longitude, + altitude: mapReport.altitude, + accuracy: mapReport.accuracy, + time: mapReport.created_at, + }); + }); + + positionHistory.sort((a, b) => a.time - b.time); + + res.json({ + position_history: positionHistory, + }); + + } catch(err) { + console.error(err); + res.status(500).json({ + message: "Something went wrong, try again later.", + }); + } +}); + app.get('/api/v1/stats/hardware-models', async (req, res) => { try { From 9722d23c61bcaaed69eb2b0d901e54b726c9a576 Mon Sep 17 00:00:00 2001 From: Tilen Komel Date: Sun, 4 Aug 2024 19:12:51 +0200 Subject: [PATCH 3/4] Working front end --- src/public/index.html | 187 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 185 insertions(+), 2 deletions(-) diff --git a/src/public/index.html b/src/public/index.html index 10bf900..9b03c6c 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -748,7 +748,14 @@
-
Position
+
+
Position
+
+ +
+
  • @@ -1589,6 +1596,56 @@
+ + +