feat: logging service

This commit is contained in:
2025-09-16 10:10:23 +02:00
parent 6a30dc0dc1
commit 8a2988cb50
20 changed files with 676 additions and 101 deletions

View File

@@ -1,8 +1,9 @@
#include "RelayService.h"
#include "spore/core/ApiServer.h"
#include "spore/services/LoggingService.h"
RelayService::RelayService(TaskManager& taskMgr, int pin)
: taskManager(taskMgr), relayPin(pin), relayOn(false) {
RelayService::RelayService(NodeContext& ctx, TaskManager& taskMgr, int pin)
: ctx(ctx), taskManager(taskMgr), relayPin(pin), relayOn(false) {
pinMode(relayPin, OUTPUT);
// Many relay modules are active LOW. Start in OFF state (relay de-energized).
digitalWrite(relayPin, HIGH);
@@ -64,13 +65,13 @@ void RelayService::turnOn() {
relayOn = true;
// Active LOW relay
digitalWrite(relayPin, LOW);
Serial.println("[RelayService] Relay ON");
LOG_INFO(ctx, "RelayService", "Relay ON");
}
void RelayService::turnOff() {
relayOn = false;
digitalWrite(relayPin, HIGH);
Serial.println("[RelayService] Relay OFF");
LOG_INFO(ctx, "RelayService", "Relay OFF");
}
void RelayService::toggle() {
@@ -83,7 +84,6 @@ void RelayService::toggle() {
void RelayService::registerTasks() {
taskManager.registerTask("relay_status_print", 5000, [this]() {
Serial.printf("[RelayService] Status - pin: %d, state: %s\n",
relayPin, relayOn ? "ON" : "OFF");
LOG_INFO(ctx, "RelayService", "Status - pin: " + String(relayPin) + ", state: " + (relayOn ? "ON" : "OFF"));
});
}