| Message Type | Direction | Purpose | Payload |
|---|---|---|---|
| HELLO | C→S | Initiate connection | client_id, version |
| CHALLENGE | S→C | Issue auth nonce | challenge (16-byte UUID) |
| CHALLENGE_RESP | C→S | Prove identity | challenge + HMAC-SHA256 sig |
| AUTH_OK | S→C | Grant access | JWT token (HS256) |
| AUTH_FAIL | S→C | Reject auth | reason string |
| HEARTBEAT | BOTH | Keep-alive probe | timestamp |
| HEARTBEAT_ACK | BOTH | Keep-alive response | echo timestamp |
| DEVICE_LIST | C→S | Request device catalog | — |
| DEVICE_LIST_ACK | S→C | Deliver device list | device_id[] |
| SUBSCRIBE | C→S | Register for RPM feeds | device_ids[] |
| SUBSCRIBE_ACK | S→C | Confirm subscriptions | ack'd device_ids[] |
| UNSUBSCRIBE | C→S | Cancel RPM feed | device_ids[] |
| DISCONNECT | BOTH | Graceful shutdown | reason |
| RPM_DATA | S→C | Telemetry frame | device_id, HR, BP, SpO2… |
| RPM_ACK | C→S | Telemetry receipt | msg_id ref |
| ERROR | BOTH | Protocol error | code + message |