- Add Spore class as unified interface for all core framework functionality - Implement setup() and begin() methods for flexible initialization pattern - Add service registration with addService() for both raw and smart pointers - Provide accessor methods for core components (getTaskManager, getContext, etc.) - Automatically include core services (Node, Network, Cluster, Task) - Update all examples to use simplified Spore framework approach - Fix circular dependency issues in include structure - Remove setHostname and setApiPort configuration methods - Add comprehensive documentation and usage examples The Spore class encapsulates all core functionality from the base example and provides a clean, unified API for the entire framework. Examples now use just spore.setup() -> add services -> spore.begin() -> spore.loop().
37 lines
856 B
C++
37 lines
856 B
C++
#include <Arduino.h>
|
|
#include "Spore.h"
|
|
#include "RelayService.h"
|
|
|
|
// Choose a default relay pin. For ESP-01 this is GPIO0. Adjust as needed for your board.
|
|
#ifndef RELAY_PIN
|
|
#define RELAY_PIN 0
|
|
#endif
|
|
|
|
// Create Spore instance with custom labels
|
|
Spore spore({
|
|
{"app", "relay"},
|
|
{"device", "actuator"},
|
|
{"pin", String(RELAY_PIN)}
|
|
});
|
|
|
|
// Create custom service
|
|
RelayService* relayService = nullptr;
|
|
|
|
void setup() {
|
|
// Initialize the Spore framework
|
|
spore.setup();
|
|
|
|
// Create and add custom service
|
|
relayService = new RelayService(spore.getTaskManager(), RELAY_PIN);
|
|
spore.addService(relayService);
|
|
|
|
// Start the API server and complete initialization
|
|
spore.begin();
|
|
|
|
Serial.println("[Main] Relay service registered and ready!");
|
|
}
|
|
|
|
void loop() {
|
|
// Run the Spore framework loop
|
|
spore.loop();
|
|
} |