feat(streaming): introduce WebSocket Streaming API bridging event bus

ApiServer: add AsyncWebSocket at /ws; accept JSON {event, payload} (string or object) and dispatch via ctx.fire; mirror all local events to clients using NodeContext::onAny.\nNodeContext: add onAny subscriber API.\nNeoPatternService: add api/neopattern/color event to set solid color.\nCluster: centralize cluster/broadcast sending in core; services delegate.\nAPI: add generic /api/node/event and /api/cluster/event endpoints in respective services.\nTests: add ws-color-client, ws-cluster-broadcast-color, http-cluster-broadcast-color.\nDocs: add StreamingAPI.md; update README and test/README.\nFixes: robust WS JSON parsing on ESP8266 and payload handling.
This commit is contained in:
2025-09-28 21:08:42 +02:00
parent f0df84dc87
commit 3cc5405292
33 changed files with 5976 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ SPORE is a cluster engine for ESP8266 microcontrollers that provides automatic n
- [Supported Hardware](#supported-hardware)
- [Architecture](#architecture)
- [Cluster Broadcast](#cluster-broadcast)
- [Streaming API](#streaming-api)
- [API Reference](#api-reference)
- [Configuration](#configuration)
- [Development](#development)
@@ -28,6 +29,7 @@ SPORE is a cluster engine for ESP8266 microcontrollers that provides automatic n
- **Health Monitoring**: Real-time node status tracking with resource monitoring
- **Event System**: Local and cluster-wide event publishing/subscription
- **Cluster Broadcast**: Centralized UDP broadcast of events (CLUSTER_EVENT)
- **Streaming API**: WebSocket bridge for real-time event send/receive
- **Over-The-Air Updates**: Seamless firmware updates across the cluster
- **REST API**: HTTP-based cluster management and monitoring
- **Capability Discovery**: Automatic API endpoint and service capability detection
@@ -134,6 +136,23 @@ Notes:
📖 See the dedicated guide: [`docs/ClusterBroadcast.md`](./docs/ClusterBroadcast.md)
## Streaming API
Real-time event bridge available at `/ws` using WebSocket.
- Send JSON `{ event, payload }` to dispatch events via `ctx.fire`.
- Receive all local events as `{ event, payload }`.
Examples:
```json
{ "event": "api/neopattern/color", "payload": { "color": "#FF0000", "brightness": 128 } }
```
```json
{ "event": "cluster/broadcast", "payload": { "event": "api/neopattern/color", "data": { "color": "#00FF00" } } }
```
📖 See the dedicated guide: [`docs/StreamingAPI.md`](./docs/StreamingAPI.md)
## API Reference
The system provides a comprehensive RESTful API for monitoring and controlling the embedded device. All endpoints return JSON responses and support standard HTTP status codes.