Compare commits
5 Commits
feat/web-c
...
393eab2b45
Author | SHA256 | Date | |
---|---|---|---|
393eab2b45 | |||
097cb44649 | |||
95adba8e9a | |||
a4a8b6c3c1 | |||
aa3c250c2e |
@ -10,7 +10,7 @@ TODO
|
||||
### Database
|
||||
**Change name of database and credentials as you like!**
|
||||
|
||||
- Create new database: `CREATE DATABASE locationhub;`
|
||||
- Create new database: `CREATE DATABASE dev_locationhub;`
|
||||
- Create new user for database: `GRANT ALL PRIVILEGES ON dev_locationhub.* TO 'dbuser'@'localhost' IDENTIFIED BY '1234';`
|
||||
- Import tables: `/usr/bin/mariadb -u dbuser -p1234 dev_locationhub < server/sql/tables.sql`
|
||||
|
||||
|
@ -8,6 +8,34 @@ domainEventEmitter.on(
|
||||
TtnMessageReceivedEventName,
|
||||
async (event: TtnMessageReceivedEvent) => {
|
||||
console.log(event);
|
||||
// TODO Hendrik 🚀
|
||||
|
||||
if (!event.ttnGateways || event.ttnGateways.length === 0) {
|
||||
console.log("No TTN Gateway location received!")
|
||||
} else {
|
||||
let totalWeight = 0;
|
||||
let weightedLatitude = 0;
|
||||
let weightedLongitude = 0;
|
||||
|
||||
event.ttnGateways.forEach(gw => {
|
||||
const weight = 1 / Math.abs(gw.rssi); // Higher RSSI (closer to 0) gives more weight
|
||||
totalWeight += weight;
|
||||
weightedLatitude += gw.latitude * weight;
|
||||
weightedLongitude += gw.longitude * weight;
|
||||
});
|
||||
|
||||
// Calculate the weighted average to get the virtual location
|
||||
const virtualLocation = {
|
||||
latitude: weightedLatitude / totalWeight,
|
||||
longitude: weightedLongitude / totalWeight
|
||||
};
|
||||
|
||||
console.log("Tracker location based on TTN Gateway location:", virtualLocation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -25,5 +25,5 @@ app.use("/api/locations", locationRoutes);
|
||||
app.use("/api/ttn", ttnRoutes);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 Server läuft auf http://localhost:${PORT}`);
|
||||
console.log(`🚀 Server runs here: http://localhost:${PORT}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user