Files
spore/examples/relay/main.cpp
2025-10-14 18:01:37 +02:00

38 lines
962 B
C++

#include <Arduino.h>
#include "spore/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.getContext(), spore.getTaskManager(), RELAY_PIN);
spore.registerService(relayService);
// Start the API server and complete initialization
spore.begin();
LOG_INFO("Main", "Relay service registered and ready!");
LOG_INFO("Main", "Web interface available at http://<node-ip>/relay.html");
}
void loop() {
// Run the Spore framework loop
spore.loop();
}