#include #include "light.h" #include "mqtt.h" #include "network.h" #include "ota.h" #include "pin.h" #include "TaskScheduler.h" #include "wifimanager.h" Network* network = nullptr; OTAHandler* otaHandler = nullptr; Mqtt* mqttClient = nullptr; Light *light = nullptr; Task *updateTask = nullptr; Task *mqttTickTask = nullptr; Task *mqttCheckConnectionTask = nullptr; Pin *pinR = new Pin(16, true, true, 5000, 0); // Example pin numbers, adjust as needed Pin *pinG = new Pin(17, true, true, 5000, 1); Pin *pinB = new Pin(18, true, true, 5000, 2); Pin *pinCW = new Pin(19, true, true, 5000, 3); Pin *pinWW = new Pin(21, true, true, 5000, 4); Scheduler *scheduler; void initializeScheduler(); void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("Starting Smart RGB ESP32..."); pinR->setLedLevel(0); pinG->setLedLevel(0); pinB->setLedLevel(0); pinCW->setLedLevel(0); pinWW->setLedLevel(0); network = new Network("smart-rgb"); otaHandler = new OTAHandler("smart-rgb-ota"); network->registerMDNS(); Mqtt::connect("10.238.75.81", 1883, "smart_rgb_client", "mqtt", "mqtt"); delay(1000); // Wait for MQTT connection to stabilize light = new Light(pinR, pinG, pinB, pinCW, pinWW, mqttClient, "smart_rgb_light"); initializeScheduler(); } void loop() { scheduler->execute(); // Execute the scheduler to run tasks yield(); // Yield to allow other tasks to run } void initializeScheduler() { scheduler = new Scheduler(); updateTask = new Task(TASK_SECOND, TASK_FOREVER, []() { otaHandler->poll(); // Poll for OTA updates }, scheduler, true, nullptr, nullptr); mqttTickTask = new Task(TASK_MILLISECOND * 100, TASK_FOREVER, []() { Mqtt::poll(); // Poll MQTT client for messages }, scheduler, true, nullptr, nullptr); mqttCheckConnectionTask = new Task(TASK_SECOND * 30, TASK_FOREVER, []() { Mqtt::checkConnection(); // Check MQTT connection status }, scheduler, true, nullptr, nullptr); }