66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
// 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();
|