Skip to main content

WebSocket API

Endpoint

RouteProtocolPurpose
/ws/devicesWebSocketReal-time device updates

Authentication

Client must pass JWT token as query parameter:

ws://localhost:8000/ws/devices?token=<JWT_TOKEN>

Message Types

device_list (Initial)

Sent when client connects:

{
"type": "device_list",
"devices": [
{
"id": "123...",
"key": "device-key",
"device_code": "DEV001",
"name": "Sensor-01",
"status": "online",
"temperature": 25.5,
"humidity": 60,
"last_seen": "2024-04-04T10:30:00Z",
"groups": []
}
]
}

device_update (Live)

Sent when device status changes:

{
"type": "device_update",
"device": {
"id": "123...",
"name": "Sensor-01",
"status": "online",
"temperature": 25.5,
"humidity": 60,
"last_seen": "2024-04-04T10:30:00Z"
}
}