Compare commits

...

5 Commits

3 changed files with 31 additions and 3 deletions

View File

@ -10,7 +10,7 @@ TODO
### Database ### Database
**Change name of database and credentials as you like!** **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';` - 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` - Import tables: `/usr/bin/mariadb -u dbuser -p1234 dev_locationhub < server/sql/tables.sql`

View File

@ -8,6 +8,34 @@ domainEventEmitter.on(
TtnMessageReceivedEventName, TtnMessageReceivedEventName,
async (event: TtnMessageReceivedEvent) => { async (event: TtnMessageReceivedEvent) => {
console.log(event); 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);
}
} }
); );

View File

@ -25,5 +25,5 @@ app.use("/api/locations", locationRoutes);
app.use("/api/ttn", ttnRoutes); app.use("/api/ttn", ttnRoutes);
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`🚀 Server läuft auf http://localhost:${PORT}`); console.log(`🚀 Server runs here: http://localhost:${PORT}`);
}); });