Fix jwt-token
This commit is contained in:
@@ -54,25 +54,26 @@ router.post('/devices/:id/heartbeat', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Validate heartbeat data format
|
||||
const { status, cpu_usage, memory_usage, disk_usage } = req.body;
|
||||
// Extract heartbeat data - handle both simple device heartbeats and detailed health reports
|
||||
const { type, key, status, cpu_usage, memory_usage, disk_usage, uptime, firmware_version } = req.body;
|
||||
|
||||
if (!status || typeof status !== 'string') {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: 'Invalid heartbeat data format - status is required'
|
||||
});
|
||||
}
|
||||
// For simple device heartbeats: {type:"heartbeat", key:"unique device ID"}
|
||||
// For detailed health reports: {status:"online", cpu_usage:25.5, memory_usage:60.2, etc.}
|
||||
|
||||
// Create heartbeat record
|
||||
// Create heartbeat record - handle both formats
|
||||
await Heartbeat.create({
|
||||
device_id: deviceId,
|
||||
tenant_id: device.tenant_id,
|
||||
device_key: key || ('device-' + deviceId),
|
||||
status: status || (type === 'heartbeat' ? 'online' : 'unknown'),
|
||||
timestamp: new Date(),
|
||||
status: status,
|
||||
cpu_usage: cpu_usage || null,
|
||||
uptime: uptime || null,
|
||||
memory_usage: memory_usage || null,
|
||||
disk_usage: disk_usage || null
|
||||
cpu_usage: cpu_usage || null,
|
||||
disk_usage: disk_usage || null,
|
||||
firmware_version: firmware_version || null,
|
||||
received_at: new Date(),
|
||||
raw_payload: req.body
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
|
||||
Reference in New Issue
Block a user