Compare commits

16 Commits

Author SHA256 Message Date
c0ac71ebba fix: edit wrong .gitignore :D 2025-03-22 10:22:19 +01:00
10e8e14cd6 feat: add docker compose to gitignore 2025-03-22 10:20:42 +01:00
a9c8525e6e Merge pull request 'Add timestamps of locations providers' (#18) from feat/timestamps into main
Reviewed-on: #18
Reviewed-by: Philipp Schweizer <Philipp.schw@directbox.com>
2025-02-14 21:22:57 +01:00
39c07fcef0 refactor: only search once for wifiMessage 2025-02-14 21:06:47 +01:00
52d521a6ad rename var 2025-02-08 21:24:40 +01:00
d3848ac1aa Merge branch 'main' into feat/timestamps 2025-02-08 20:54:50 +01:00
93f0c71a6c set wifi timestamp 2025-02-08 20:54:06 +01:00
5e4fd59148 refactor to use either timestamp when one is undefined 2025-02-02 20:10:29 +01:00
62a2dc2c4a fix gnss timestamp 2025-01-29 23:03:48 +01:00
59dc57a618 set gnss timestamp in location 2025-01-28 22:12:48 +01:00
452589d11d add timestamps in DB model 2025-01-28 21:55:54 +01:00
d04bdb3ac1 Merge pull request 'Add Prometheus metrics endpoint' (#14) from feat/prometheus into main
Reviewed-on: #14
Reviewed-by: Philipp Schweizer <Philipp.schw@directbox.com>
2025-01-26 10:03:28 +01:00
a745aaf9d0 add timestamps to DB model 2025-01-25 21:51:42 +01:00
51112b5870 update readme 2025-01-25 19:14:18 +01:00
262b4718fc Merge branch 'main' into feat/prometheus 2025-01-25 19:10:09 +01:00
49fe1b4ce3 README.md aktualisiert 2025-01-19 13:35:53 +01:00
9 changed files with 57 additions and 21 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
docker-compose.yml

View File

@ -11,10 +11,11 @@ We recommend using [The Things Network](https://www.thethingsnetwork.org/) (TTN)
- [Database](#database)
- [Configuration](#configuration)
2. [TTN Integration](#ttn-integration)
3. [Add a Location Tracker](#add-a-location-tracker)
3. [Prometheus Metrics](#prometheus-metrics)
4. [Add a Location Tracker](#add-a-location-tracker)
- [Onboard SenseCAP T1000-B](#onboard-sensecap-t1000-b)
- [Register SenseCAP T1000-B](#register-sensecap-t1000-b)
4. [Testing](#testing)
5. [Testing](#testing)
- [Testing Webhook](#testing-webhook)
- [Emulating Wigle API](#emulating-wigle-api)
@ -49,6 +50,9 @@ Add a addidtional header:
- Type: `authorization`
- Value: `Bearer your-very-secure-token-from-the-env-file`
### Prometheus Metrics
Use `https://your.domain.tld/api/metrics` to retrieve useful insides for monitoring.
## Add a Location Tracker
We use the [SenseCAP T1000-B](https://www.seeedstudio.com/SenseCAP-Card-Tracker-T1000-B-p-5698.html) from seeedstudio because of the fair price and multiple location providers. However, you can use any LoRaWAN-enabled tracker that is compatible with TTN and supports the required payload fields.
@ -60,7 +64,7 @@ We use the [SenseCAP T1000-B](https://www.seeedstudio.com/SenseCAP-Card-Tracker-
5. In the `Settings` tab select `The Things Network` as Platform under `LoRa`
6. Copy `Device EUI`, `AppEUI` and `AppKey`
7. Save LoRa settings
8. Under `Geolocation` select Geolocation Strategy as `Bluetooth+Wi-Fi+GNSS`
8. Under `Geolocation` select Geolocation Strategy as `GNSS+Wi-Fi`
9. Set `GNSS Max Scan Time (s)` to 120
10. Save Geolocation settings
11. Exit App with return arrow to trigger re-init of SenseCAP T1000-B

5
server/.gitignore vendored
View File

@ -308,7 +308,4 @@ cython_debug/
# Built Visual Studio Code Extensions
*.vsix
config.py
#docker
docker-compose.yml
config.py

View File

@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS lp_ttn_end_device_uplinks (
dev_eui VARCHAR(255),
join_eui VARCHAR(255),
dev_addr VARCHAR(255),
received_at_utc DATE,
received_at_utc DATE NOT NULL,
battery NUMERIC,
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS wifi_scan (
lp_ttn_end_device_uplinks_id UUID,
mac VARCHAR(255),
rssi NUMERIC,
scanned_at_utc TIMESTAMP NOT NULL,
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (lp_ttn_end_device_uplinks_id) REFERENCES lp_ttn_end_device_uplinks(lp_ttn_end_device_uplinks_id)
@ -63,6 +64,7 @@ CREATE TABLE IF NOT EXISTS location (
gnss_longitude DOUBLE,
ttn_gw_latitude DOUBLE,
ttn_gw_longitude DOUBLE,
gnss_location_at_utc TIMESTAMP,
created_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at_utc TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (lp_ttn_end_device_uplinks_id) REFERENCES lp_ttn_end_device_uplinks(lp_ttn_end_device_uplinks_id)

View File

@ -42,23 +42,38 @@ router.post(
)?.measurementValue,
});
const messageData = message.uplink_message.decoded_payload?.messages[0];
const latitudeData = messageData?.find((e) => e.type === "Latitude");
const longitudeData = messageData?.find((e) => e.type === "Longitude");
const gnnsLocation = {
latitude: message.uplink_message.decoded_payload?.messages[0].find(
(e) => e.type === "Latitude"
)?.measurementValue,
longitude: message.uplink_message.decoded_payload?.messages[0].find(
(e) => e.type === "Longitude"
)?.measurementValue,
latitude: latitudeData?.measurementValue,
longitude: longitudeData?.measurementValue,
};
const gnssTimestamp = {
timestamp: latitudeData?.timestamp
? new Date(latitudeData.timestamp)
: longitudeData?.timestamp
? new Date(longitudeData.timestamp)
: undefined,
};
const wifiMessage =
message.uplink_message.decoded_payload?.messages[0].find(
(e) => e.type === "Wi-Fi Scan"
);
const wifiScans =
message.uplink_message.decoded_payload?.messages[0]
.find((e) => e.type === "Wi-Fi Scan")
?.measurementValue?.map((w) => ({
lp_ttn_end_device_uplinks_id,
mac: w.mac,
rssi: w.rssi,
})) ?? [];
wifiMessage?.measurementValue?.map((w) => ({
lp_ttn_end_device_uplinks_id,
mac: w.mac,
rssi: w.rssi,
scanned_at_utc: wifiMessage?.timestamp
? new Date(wifiMessage.timestamp)
: undefined,
})) ?? [];
const ttnGatewayReceptions = message.uplink_message.rx_metadata.map(
(g) => ({
@ -98,6 +113,7 @@ router.post(
longitude: gnnsLocation.longitude,
}
: undefined,
gnss_timestamp: gnssTimestamp.timestamp,
});
};
createDatabaseEntries().then();

View File

@ -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_location_at_utc!: Date;
public created_at_utc!: Date;
public updated_at_utc!: Date;
}
@ -42,6 +43,9 @@ Location.init(
ttn_gw_longitude: {
type: DataTypes.NUMBER,
},
gnss_location_at_utc: {
type: DataTypes.DATE,
},
created_at_utc: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,

View File

@ -6,6 +6,7 @@ export class WifiScan extends Model {
public wifi_scan_id!: string;
public mac!: string;
public rssi!: number;
public scanned_at_utc!: Date;
public created_at_utc!: Date;
public updated_at_utc!: Date;
}
@ -30,6 +31,11 @@ WifiScan.init(
type: DataTypes.NUMBER,
allowNull: false,
},
scanned_at_utc: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
allowNull: false,
},
created_at_utc: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,

View File

@ -9,6 +9,7 @@ interface CreateLocationParams {
wifi?: Coordinates;
gnss?: Coordinates;
ttn_gw?: Coordinates;
gnss_timestamp?: Date;
}
interface CreateLocationTriangulationParams {
@ -19,6 +20,7 @@ interface CreateLocationTriangulationParams {
}[];
ttn_gw: LocationSignal[];
gnss?: Coordinates;
gnss_timestamp?: Date;
}
interface LocationSignal extends Coordinates {
@ -75,6 +77,7 @@ export class LocationService {
ttn_gw_longitude: data.ttn_gw?.longitude,
gnss_latitude: data.gnss?.latitude,
gnss_longitude: data.gnss?.longitude,
gnss_location_at_utc: data.gnss_timestamp,
});
}
@ -91,6 +94,7 @@ export class LocationService {
wifi: wifi_location,
ttn_gw: gateway_location,
gnss: data.gnss,
gnss_timestamp: data.gnss_timestamp,
});
}

View File

@ -5,12 +5,14 @@ interface CreateWifiScanParams {
lp_ttn_end_device_uplinks_id: string;
mac: string;
rssi: number;
scanned_at_utc?: Date;
}
interface UpdateWifiScanParams {
wifi_scan_id: string;
mac?: string;
rssi?: number;
scanned_at_utc?: Date;
}
@injectable()