📝 Adds websocket docs

This commit is contained in:
Rune Harlyk
2026-01-03 18:07:23 +01:00
committed by nikguin04
parent 7cb5c06524
commit 5295ad56c8
2 changed files with 53 additions and 0 deletions
+6
View File
@@ -72,3 +72,9 @@ The back end exposes a number of API endpoints which are referenced in the table
| POST | /api/files/delete | Delete file |
| POST | /api/files/edit | Edit file |
| POST | /api/files/mkdir | Create directory |
## WebSocket
Real-time communication is handled via WebSocket at `/api/ws` using Protocol Buffers.
See [websocket.md](websocket.md) for the full WebSocket API documentation.
+47
View File
@@ -0,0 +1,47 @@
# WebSocket API
The ESP32 exposes a WebSocket endpoint at `/api/ws` for real-time bidirectional communication using Protocol Buffers (protobuf).
## Connection
Connect to the WebSocket at:
```
ws://<device-ip>/api/ws
```
All messages are binary-encoded protobuf `Message` wrappers defined in `platform_shared/message.proto`.
## Message Flow
The WebSocket supports three communication patterns:
1. **Client to Server**: Commands like controller input, mode changes, servo control
2. **Server to Client**: Periodic data broadcasts like IMU, system metrics, RSSI, servo angles
3. **Request-Response**: Use `socket.request()` for operations requiring a response
## Example: Sending Controller Input
```typescript
import { Message, ControllerData } from "./proto/message";
const input: ControllerData = {
left: { x: 0.5, y: 0.0 },
right: { x: 0.0, y: 0.0 },
height: 0.1,
speed: 1.0,
s1: 0.0,
};
const message = Message.encode({ ControllerData: input }).finish();
socket.send(message);
```
## Example: Request-Response
```typescript
const response = await socket.request({ imuCalibrateExecute: {} });
const result = response.imuCalibrateData;
```
See `platform_shared/message.proto` for all available message types and their definitions.