diff --git a/drone_simulator.py b/drone_simulator.py index ab12b84..3929980 100644 --- a/drone_simulator.py +++ b/drone_simulator.py @@ -101,7 +101,7 @@ class SwedishDroneSimulator: def generate_devices(self, num_devices: int) -> List[DroneDevice]: """Generate drone detection devices at Swedish sensitive locations""" devices = [] - device_id_base = 1001 # Use simple device IDs starting from 1001 + device_id_base = 1941875380 # Use the same IDs as in database setup all_locations = [] for category, locations in SWEDISH_LOCATIONS.items(): diff --git a/server/routes/detectors.js b/server/routes/detectors.js index 2fbb6cd..54fdba7 100644 --- a/server/routes/detectors.js +++ b/server/routes/detectors.js @@ -105,7 +105,7 @@ router.post('/', validateRequest(detectorSchema), async (req, res) => { // Handle heartbeat payload async function handleHeartbeat(req, res) { - const { type, key, device_id, ...heartbeatData } = req.body; + const { type, key, device_id, geo_lat, geo_lon, location_description, ...heartbeatData } = req.body; console.log(`💓 Heartbeat received from device key: ${key}`); console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2)); @@ -124,13 +124,28 @@ async function handleHeartbeat(req, res) { let device = await Device.findOne({ where: { id: deviceId } }); if (!device) { - // Create new device as unapproved - device = await Device.create({ + // Create new device as unapproved with coordinates if provided + const deviceData = { id: deviceId, name: `Device ${deviceId}`, last_heartbeat: new Date(), is_approved: false - }); + }; + + // Add coordinates if provided in heartbeat + if (geo_lat && geo_lon) { + deviceData.geo_lat = geo_lat; + deviceData.geo_lon = geo_lon; + console.log(`📍 Setting device coordinates: ${geo_lat}, ${geo_lon}`); + } + + // Add location description if provided + if (location_description) { + deviceData.location_description = location_description; + console.log(`📍 Setting device location: ${location_description}`); + } + + device = await Device.create(deviceData); // Emit notification for new device requiring approval req.io.emit('new_device_pending', {