save TTN GW based location into DB
This commit is contained in:
parent
c27763fc11
commit
4994b8a246
@ -3,12 +3,23 @@ import {
|
||||
TtnMessageReceivedEvent,
|
||||
TtnMessageReceivedEventName,
|
||||
} from "../event/ttnMessageReceivedEvent";
|
||||
import { container } from "tsyringe";
|
||||
import { LocationService } from "../services/locationService";
|
||||
|
||||
const locationService = container.resolve(LocationService);
|
||||
|
||||
domainEventEmitter.on(
|
||||
TtnMessageReceivedEventName,
|
||||
async (event: TtnMessageReceivedEvent) => {
|
||||
console.log(event);
|
||||
|
||||
var wifi_based_latitude!: number;
|
||||
var wifi_based_longitude!: number;
|
||||
var gnss_based_latitude!: number; // Should this be set here?
|
||||
var gnss_based_longitude!: number; // Should this be set here?
|
||||
var ttn_gw_based_latitude!: number;
|
||||
var ttn_gw_based_longitude!: number;
|
||||
|
||||
if (!event.ttnGateways || event.ttnGateways.length === 0) {
|
||||
console.log("No TTN Gateway location received!")
|
||||
} else {
|
||||
@ -30,12 +41,23 @@ domainEventEmitter.on(
|
||||
};
|
||||
|
||||
console.log("Tracker location based on TTN Gateway location:", virtualLocation);
|
||||
ttn_gw_based_latitude = virtualLocation.latitude;
|
||||
ttn_gw_based_longitude = virtualLocation.longitude;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// TODO: parse Wifi location here
|
||||
}
|
||||
|
||||
const newLocation = await locationService.createLocation({
|
||||
lp_ttn_end_device_uplinks_id: event.lp_ttn_end_device_uplinks_id,
|
||||
ttn_gw_latitude: ttn_gw_based_latitude,
|
||||
ttn_gw_longitude: ttn_gw_based_longitude,
|
||||
});
|
||||
|
||||
|
||||
|
||||
console.log(newLocation)
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user