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
NeoPattern Service for Spore Framework
This example demonstrates how to integrate a NeoPixel pattern service with the Spore framework. It provides a comprehensive LED strip control system with multiple animation patterns and REST API endpoints.
Features
- Multiple Animation Patterns: Rainbow cycle, theater chase, color wipe, scanner, fade, and fire effects
- REST API Control: Full HTTP API for pattern control and configuration
- Real-time Updates: Smooth pattern transitions and real-time parameter changes
- State Management: Persistent state with JSON serialization
- Spore Integration: Built on the Spore framework for networking and task management
Hardware Requirements
- ESP32 or compatible microcontroller
- NeoPixel LED strip (WS2812B or compatible)
- Appropriate power supply for your LED strip
Configuration
Edit NeoPixelConfig.h to configure your setup:
static constexpr int DEFAULT_PIN = 2;
static constexpr int DEFAULT_LENGTH = 8;
static constexpr int DEFAULT_BRIGHTNESS = 100;
static constexpr int DEFAULT_UPDATE_INTERVAL = 100;
static constexpr int DEFAULT_COLOR = 0xFF0000; // Red
API Endpoints
Status Information
GET /api/neopattern/status- Get current status and configurationGET /api/neopattern/patterns- List available patterns
Pattern Control
POST /api/neopattern- Control pattern parameterspattern: Pattern name (none, rainbow_cycle, theater_chase, color_wipe, scanner, fade, fire)color: Primary color (hex string like "#FF0000" or "0xFF0000")color2: Secondary color for two-color patternsbrightness: Brightness level (0-255)total_steps: Number of steps for patternsdirection: Pattern direction (forward, reverse)interval: Update interval in milliseconds
State Management
POST /api/neopattern/state- Set complete state via JSON
Example API Usage
Set a rainbow cycle pattern
curl -X POST http://esp32-ip/api/neopattern \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "pattern=rainbow_cycle&interval=50"
Set custom colors for theater chase
curl -X POST http://esp32-ip/api/neopattern \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "pattern=theater_chase&color=0xFF0000&color2=0x0000FF&brightness=150"
Set complete state via JSON
curl -X POST http://esp32-ip/api/neopattern/state \
-H "Content-Type: application/json" \
-d '{
"pattern": 3,
"color": 16711680,
"color2": 255,
"totalSteps": 32,
"brightness": 128
}'
Available Patterns
- none - Static color display
- rainbow_cycle - Smooth rainbow cycling
- theater_chase - Moving dots with two colors
- color_wipe - Progressive color filling
- scanner - Scanning light effect
- fade - Smooth color transition
- fire - Fire simulation effect
Building and Flashing
- Install PlatformIO
- Configure your
platformio.inito include the Spore framework - Build and upload:
pio run -t upload
Integration with Spore Framework
This service integrates with the Spore framework by:
- Extending the
Servicebase class - Using
TaskManagerfor pattern updates - Registering REST API endpoints with
ApiServer - Following Spore's logging and configuration patterns
The service automatically registers itself with the Spore framework and provides all functionality through the standard Spore API infrastructure.
Customization
To add new patterns:
- Add the pattern enum to
NeoPatternService.h - Implement the pattern logic in
NeoPattern.cpp - Add the pattern updater to
registerPatterns()inNeoPatternService.cpp - Update the pattern mapping in
nameToPatternMap
Troubleshooting
- LEDs not lighting: Check wiring and power supply
- Patterns not updating: Verify the update interval and task registration
- API not responding: Check network configuration and Spore framework setup
- Memory issues: Reduce LED count or pattern complexity
Dependencies
- Spore Framework
- Adafruit NeoPixel library
- ArduinoJson
- ESP32 Arduino Core