diff --git a/check_devices.js b/check_devices.js new file mode 100644 index 0000000..ffc8b62 --- /dev/null +++ b/check_devices.js @@ -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(); diff --git a/debug_device_status.py b/debug_device_status.py index 7299d1a..c5f4c62 100644 --- a/debug_device_status.py +++ b/debug_device_status.py @@ -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: