diff --git a/README.md b/README.md index a98dba7..e32426c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ SPORE is a cluster engine for ESP8266 microcontrollers that provides automatic n - [Features](#features) - [Supported Hardware](#supported-hardware) - [Architecture](#architecture) +- [Cluster Broadcast](#cluster-broadcast) - [API Reference](#api-reference) - [Configuration](#configuration) - [Development](#development) @@ -26,6 +27,7 @@ SPORE is a cluster engine for ESP8266 microcontrollers that provides automatic n - **Service Registry**: Dynamic API endpoint discovery and registration - **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) - **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 @@ -103,6 +105,35 @@ void setup() { **Examples:** See [`examples/base/`](./examples/base/) for basic usage and [`examples/relay/`](./examples/relay/) for custom service integration. +## Cluster Broadcast + +Broadcast an event to all peers using the centralized core broadcaster. Services never touch UDP directly; instead they fire a local event that the core transmits as a `CLUSTER_EVENT`. + +Usage: + +```cpp +// 1) Apply locally via the same event your service already handles +JsonDocument payload; +payload["pattern"] = "rainbow_cycle"; +payload["brightness"] = 100; +String payloadStr; serializeJson(payload, payloadStr); +ctx.fire("api/neopattern", &payloadStr); + +// 2) Broadcast to peers via the core +JsonDocument envelope; +envelope["event"] = "api/neopattern"; +envelope["data"] = payloadStr; // JSON string +String eventJson; serializeJson(envelope, eventJson); +ctx.fire("cluster/broadcast", &eventJson); +``` + +Notes: +- The core sends subnet-directed broadcasts (e.g., 192.168.1.255) for reliability. +- Peers receive `CLUSTER_EVENT` and forward to local subscribers with `ctx.fire(event, data)`. +- `data` can be a JSON string or nested JSON; receivers handle both. + +📖 See the dedicated guide: [`docs/ClusterBroadcast.md`](./docs/ClusterBroadcast.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.