Fix jwt-token
This commit is contained in:
65
check_devices.js
Normal file
65
check_devices.js
Normal file
@@ -0,0 +1,65 @@
|
||||
// Simple diagnostic script to check device status
|
||||
// Run this with: node check_devices.js
|
||||
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.join(__dirname, 'server', '.env') });
|
||||
const { sequelize, Device } = require('./server/models');
|
||||
|
||||
async function checkDevices() {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Database connected successfully.');
|
||||
|
||||
const allDevices = await Device.findAll({
|
||||
attributes: ['id', 'name', 'is_approved', 'is_active', 'geo_lat', 'geo_lon', 'last_heartbeat'],
|
||||
order: [['id', 'ASC']]
|
||||
});
|
||||
|
||||
console.log('\n=== ALL DEVICES ===');
|
||||
console.log(`Total devices: ${allDevices.length}`);
|
||||
|
||||
if (allDevices.length === 0) {
|
||||
console.log('No devices found in database.');
|
||||
return;
|
||||
}
|
||||
|
||||
allDevices.forEach(device => {
|
||||
console.log(`\nDevice ${device.id}:`);
|
||||
console.log(` Name: ${device.name}`);
|
||||
console.log(` Approved: ${device.is_approved}`);
|
||||
console.log(` Active: ${device.is_active}`);
|
||||
console.log(` Coordinates: ${device.geo_lat}, ${device.geo_lon}`);
|
||||
console.log(` Last Heartbeat: ${device.last_heartbeat}`);
|
||||
});
|
||||
|
||||
const approvedDevices = allDevices.filter(d => d.is_approved);
|
||||
const activeDevices = allDevices.filter(d => d.is_active);
|
||||
const devicesWithCoords = allDevices.filter(d => d.geo_lat && d.geo_lon);
|
||||
const mapEligible = allDevices.filter(d => d.is_active && d.geo_lat && d.geo_lon);
|
||||
|
||||
console.log('\n=== SUMMARY ===');
|
||||
console.log(`Approved devices: ${approvedDevices.length}`);
|
||||
console.log(`Active devices: ${activeDevices.length}`);
|
||||
console.log(`Devices with coordinates: ${devicesWithCoords.length}`);
|
||||
console.log(`Map-eligible devices (active + coordinates): ${mapEligible.length}`);
|
||||
|
||||
if (mapEligible.length === 0) {
|
||||
console.log('\n❌ NO DEVICES WILL APPEAR ON MAP');
|
||||
console.log('Devices need to be approved to become active and appear on the map.');
|
||||
console.log('\nTo fix this, run:');
|
||||
console.log('UPDATE devices SET is_approved = true, is_active = true WHERE is_approved = false;');
|
||||
} else {
|
||||
console.log('\n✅ These devices should appear on map:');
|
||||
mapEligible.forEach(device => {
|
||||
console.log(` - Device ${device.id} at ${device.geo_lat}, ${device.geo_lon}`);
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error checking devices:', error);
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
checkDevices();
|
||||
@@ -99,6 +99,7 @@ def debug_device_status():
|
||||
print(f" Name: {stockholm_device.get('name', 'N/A')}")
|
||||
print(f" Active: {stockholm_device.get('is_active', False)}")
|
||||
print(f" Approved: {stockholm_device.get('is_approved', False)}")
|
||||
print(f" Coordinates: {stockholm_device.get('geo_lat', 'N/A')}, {stockholm_device.get('geo_lon', 'N/A')}")
|
||||
print(f" Last Heartbeat: {stockholm_device.get('last_heartbeat', 'Never')}")
|
||||
print(f" Heartbeat Interval: {stockholm_device.get('heartbeat_interval', 'Not set')} seconds")
|
||||
|
||||
@@ -131,7 +132,8 @@ def debug_device_status():
|
||||
print("❌ Stockholm device not found")
|
||||
print("Available devices:")
|
||||
for device in devices:
|
||||
print(f" - ID {device['id']}: {device.get('name', 'Unnamed')}")
|
||||
coords = f"({device.get('geo_lat', 'N/A')}, {device.get('geo_lon', 'N/A')})"
|
||||
print(f" - ID {device['id']}: {device.get('name', 'Unnamed')} at {coords}")
|
||||
else:
|
||||
print(f"❌ No devices found")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user