Fix jwt-token
This commit is contained in:
@@ -101,7 +101,7 @@ class SwedishDroneSimulator:
|
|||||||
def generate_devices(self, num_devices: int) -> List[DroneDevice]:
|
def generate_devices(self, num_devices: int) -> List[DroneDevice]:
|
||||||
"""Generate drone detection devices at Swedish sensitive locations"""
|
"""Generate drone detection devices at Swedish sensitive locations"""
|
||||||
devices = []
|
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 = []
|
all_locations = []
|
||||||
for category, locations in SWEDISH_LOCATIONS.items():
|
for category, locations in SWEDISH_LOCATIONS.items():
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
|||||||
|
|
||||||
// Handle heartbeat payload
|
// Handle heartbeat payload
|
||||||
async function handleHeartbeat(req, res) {
|
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(`💓 Heartbeat received from device key: ${key}`);
|
||||||
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
|
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 } });
|
let device = await Device.findOne({ where: { id: deviceId } });
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
// Create new device as unapproved
|
// Create new device as unapproved with coordinates if provided
|
||||||
device = await Device.create({
|
const deviceData = {
|
||||||
id: deviceId,
|
id: deviceId,
|
||||||
name: `Device ${deviceId}`,
|
name: `Device ${deviceId}`,
|
||||||
last_heartbeat: new Date(),
|
last_heartbeat: new Date(),
|
||||||
is_approved: false
|
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
|
// Emit notification for new device requiring approval
|
||||||
req.io.emit('new_device_pending', {
|
req.io.emit('new_device_pending', {
|
||||||
|
|||||||
Reference in New Issue
Block a user