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
61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#include <Arduino.h>
|
|
#include "spore/Spore.h"
|
|
#include "spore/util/Logging.h"
|
|
#include "NeoPatternService.h"
|
|
#include "NeoPixelConfig.h"
|
|
|
|
// Configuration constants
|
|
#ifndef NEOPIXEL_PIN
|
|
#define NEOPIXEL_PIN 2
|
|
#endif
|
|
|
|
#ifndef NEOPIXEL_LENGTH
|
|
#define NEOPIXEL_LENGTH 8
|
|
#endif
|
|
|
|
#ifndef NEOPIXEL_BRIGHTNESS
|
|
#define NEOPIXEL_BRIGHTNESS 100
|
|
#endif
|
|
|
|
#ifndef NEOPIXEL_UPDATE_INTERVAL
|
|
#define NEOPIXEL_UPDATE_INTERVAL 100
|
|
#endif
|
|
|
|
// Create Spore instance with custom labels
|
|
Spore spore({
|
|
{"app", "neopattern"},
|
|
{"role", "led"},
|
|
{"pixels", String(NEOPIXEL_LENGTH)},
|
|
{"pin", String(NEOPIXEL_PIN)}
|
|
});
|
|
|
|
// Create custom service
|
|
NeoPatternService* neoPatternService = nullptr;
|
|
|
|
void setup() {
|
|
// Initialize the Spore framework
|
|
spore.setup();
|
|
|
|
// Create configuration
|
|
NeoPixelConfig config(
|
|
NEOPIXEL_PIN,
|
|
NEOPIXEL_LENGTH,
|
|
NEOPIXEL_BRIGHTNESS,
|
|
NEOPIXEL_UPDATE_INTERVAL
|
|
);
|
|
|
|
// Create and add custom service
|
|
neoPatternService = new NeoPatternService(spore.getContext(), spore.getTaskManager(), config);
|
|
spore.addService(neoPatternService);
|
|
|
|
// Start the API server and complete initialization
|
|
spore.begin();
|
|
|
|
LOG_INFO("Main", "NeoPattern service registered and ready!");
|
|
}
|
|
|
|
void loop() {
|
|
// Run the Spore framework loop
|
|
spore.loop();
|
|
}
|