- Restructure include/ and src/ directories with logical grouping - Move core components to spore/core/ (NodeContext, NetworkManager, TaskManager, ClusterManager, ApiServer) - Move services to spore/services/ (NodeService, NetworkService, ClusterService, TaskService) - Move types to spore/types/ (NodeInfo, ApiTypes, Config) - Move internal components to spore/internal/ (Globals) - Update all #include statements to use new namespace paths - Update platformio.ini build filters for all environments - Update all example files to use new include paths - Maintain backward compatibility for public API - Improve code organization, maintainability, and scalability This reorganization follows modern C++ project structure patterns and provides clear separation between public API, internal implementation, and utilities. All examples compile successfully with the new structure.
Relay Service Example
A minimal example that demonstrates the Spore framework with a custom RelayService. The Spore framework automatically handles all core functionality (WiFi, clustering, API server, task management) while allowing easy registration of custom services.
- Default relay pin:
GPIO0(ESP-01). Override with-DRELAY_PIN=<pin>. - WiFi and API port are configured in
src/Config.cpp.
Spore Framework Usage
This example demonstrates the simplified Spore framework approach:
#include <Arduino.h>
#include "Spore.h"
#include "RelayService.h"
Spore spore({
{"app", "relay"},
{"device", "actuator"},
{"pin", String(RELAY_PIN)}
});
RelayService* relayService = nullptr;
void setup() {
spore.setup();
relayService = new RelayService(spore.getTaskManager(), RELAY_PIN);
spore.addService(relayService);
spore.begin();
}
void loop() {
spore.loop();
}
The Spore framework automatically provides:
- WiFi connectivity management
- Cluster discovery and management
- REST API server with core endpoints
- Task scheduling and execution
- Node status monitoring
Build & Upload
- ESP‑01S:
pio run -e esp01_1m_relay -t upload
- D1 Mini:
pio run -e d1_mini_relay -t upload
Monitor serial logs:
pio device monitor -b 115200
Assume the device IP is 192.168.1.50 below (replace with your device's IP shown in serial output).
Relay API
- Get relay status
curl http://192.168.1.50/api/relay/status
- Turn relay ON
curl -X POST http://192.168.1.50/api/relay -d state=on
- Turn relay OFF
curl -X POST http://192.168.1.50/api/relay -d state=off
- Toggle relay
curl -X POST http://192.168.1.50/api/relay -d state=toggle
Notes:
- Requests use
application/x-www-form-urlencodedby default when usingcurl -d.
Task Management (optional)
The example registers a periodic task relay_status_print that logs the current relay state.
- Fetch all task statuses
curl http://192.168.1.50/api/tasks/status
- Query a specific task status
curl -X POST http://192.168.1.50/api/tasks/control \
-d task=relay_status_print -d action=status
- Enable / Disable the task
curl -X POST http://192.168.1.50/api/tasks/control \
-d task=relay_status_print -d action=enable
curl -X POST http://192.168.1.50/api/tasks/control \
-d task=relay_status_print -d action=disable
General System Endpoints (optional)
- Node status
curl http://192.168.1.50/api/node/status
- Restart device
curl -X POST http://192.168.1.50/api/node/restart