From 59dc57a618c3de9b68c74dc5e7de13230d602631fb195f736b7d361cadb3dc13 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 28 Jan 2025 22:12:48 +0100 Subject: [PATCH] set gnss timestamp in location --- server/src/controller/ttnController.ts | 11 +++++++++++ server/src/models/location.ts | 1 + server/src/services/locationService.ts | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/server/src/controller/ttnController.ts b/server/src/controller/ttnController.ts index 28c88b1..dc8dc35 100644 --- a/server/src/controller/ttnController.ts +++ b/server/src/controller/ttnController.ts @@ -51,6 +51,14 @@ router.post( )?.measurementValue, }; + const gnssTimestamp = { + timestamp: message.uplink_message.decoded_payload?.messages[0].find( + (e) => e.type === "Latitude" + )?.timestamp + }; + + + const wifiScans = message.uplink_message.decoded_payload?.messages[0] .find((e) => e.type === "Wi-Fi Scan") @@ -96,8 +104,11 @@ router.post( ? { latitude: gnnsLocation.latitude, longitude: gnnsLocation.longitude, + } : undefined, + + gnss_timestamp: new Date(gnssTimestamp.timestamp), }); }; createDatabaseEntries().then(); diff --git a/server/src/models/location.ts b/server/src/models/location.ts index c4b5dff..728645c 100644 --- a/server/src/models/location.ts +++ b/server/src/models/location.ts @@ -10,6 +10,7 @@ export class Location extends Model { public gnss_longitude!: number; public ttn_gw_latitude!: number; public ttn_gw_longitude!: number; + public gnss_timestamp!: Date; public created_at_utc!: Date; public updated_at_utc!: Date; } diff --git a/server/src/services/locationService.ts b/server/src/services/locationService.ts index cb8f10b..ea96d2c 100644 --- a/server/src/services/locationService.ts +++ b/server/src/services/locationService.ts @@ -8,6 +8,7 @@ interface CreateLocationParams { wifi?: Coordinates; gnss?: Coordinates; ttn_gw?: Coordinates; + gnss_timestamp?: Date; } interface CreateLocationTriangulationParams { @@ -18,6 +19,7 @@ interface CreateLocationTriangulationParams { }[]; ttn_gw: LocationSignal[]; gnss?: Coordinates; + gnss_timestamp: Date; } interface LocationSignal extends Coordinates { @@ -65,6 +67,7 @@ export class LocationService { ttn_gw_longitude: data.ttn_gw?.longitude, gnss_latitude: data.gnss?.latitude, gnss_longitude: data.gnss?.longitude, + gnss_timestamp: data.gnss_timestamp, }); } @@ -81,6 +84,7 @@ export class LocationService { wifi: wifi_location, ttn_gw: gateway_location, gnss: data.gnss, + }); }