feat(cluster, neopattern): add CLUSTER_EVENT and broadcast handling

Add CLUSTER_EVENT message type and end-to-end handling across cluster and NeoPattern example.\n\nCluster protocol / core:\n- Add ClusterProtocol::CLUSTER_EVENT_MSG\n- ClusterManager: register predicate/handler for CLUSTER_EVENT\n- Robust parsing: accept data as string or nested JSON; serialize nested data to string before firing\n- Add defensive null-termination for full UDP reads; log unknown message head if no handler matches\n- Logging: source IP, payload length, missing fields, and pre-fire event details\n\nNeoPatternService:\n- Constructor now accepts NodeContext and registers ctx.on(api/neopattern) handler\n- /api/neopattern: add optional boolean 'broadcast' flag\n- If broadcast=true: build event payload and send CLUSTER_EVENT over UDP (subnet-directed broadcast); log target and payload size; also fire locally so sender applies immediately\n- Implement applyControlParams with robust ArduinoJson is<T>() checks (replaces deprecated containsKey()) and flexible string/number parsing for color, brightness, steps, interval\n- Minor fixes: include Globals for ClusterProtocol, include ESP8266WiFi for broadcast IP calc, safer brightness clamping\n\nExample:\n- Update neopattern main to pass NodeContext into NeoPatternService\n\nResult:\n- Nodes receive and process CLUSTER_EVENT (api/neopattern) via ctx.fire/ctx.on\n- Broadcast reliably reaches peers; parsing handles both stringified and nested JSON data\n- Additional logs aid diagnosis of delivery/format issues and remove deprecation warnings
This commit is contained in:
2025-09-28 13:18:25 +02:00
parent 2bb0742850
commit cabf857bbd
6 changed files with 217 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include "spore/Service.h"
#include "spore/core/TaskManager.h"
#include "spore/core/NodeContext.h"
#include "NeoPattern.h"
#include "NeoPatternState.h"
#include "NeoPixelConfig.h"
@@ -25,7 +26,7 @@ public:
REVERSE
};
NeoPatternService(TaskManager& taskMgr, const NeoPixelConfig& config);
NeoPatternService(NodeContext& ctx, TaskManager& taskMgr, const NeoPixelConfig& config);
~NeoPatternService();
void registerEndpoints(ApiServer& api) override;
@@ -49,6 +50,8 @@ private:
void registerTasks();
void registerPatterns();
void update();
void registerEventHandlers();
bool applyControlParams(const JsonObject& obj);
// Pattern updaters
void updateRainbowCycle();
@@ -80,6 +83,7 @@ private:
String getPatternDescription(const String& name) const;
TaskManager& taskManager;
NodeContext& ctx;
NeoPattern* neoPattern;
NeoPixelConfig config;
NeoPatternState currentState;