wip with light and mqtt working

This commit is contained in:
2025-08-03 00:34:05 +02:00
parent 8a0c502dae
commit f5fff82fad
9 changed files with 502 additions and 6 deletions

View File

@@ -1,11 +1,28 @@
#include <Arduino.h>
#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(14, true, true, 5000, 0); // Example pin numbers, adjust as needed
Pin *pinG = new Pin(15, true, true, 5000, 1);
Pin *pinB = new Pin(16, true, true, 5000, 2);
Scheduler *scheduler;
void initializeScheduler();
void setup() {
// put your setup code here, to run once:
@@ -14,9 +31,27 @@ void setup() {
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, mqttClient, "smart_rgb_light");
initializeScheduler();
}
void loop() {
otaHandler->poll(); // Handle OTA updates
delay(500);
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);
}