Ajout Thermostat

This commit is contained in:
Serge NOEL
2026-03-11 11:50:45 +01:00
parent d3db51dba2
commit ab74dc5fbe
14 changed files with 496 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#include "mqtt_handler.h"
#include "thermostat.h"
#include <ArduinoJson.h>
String mqtt_device_id = "thermo1";
String mqtt_temp_topic = "home/room/temperature/thermo1";
void setup_mqtt(PubSubClient& client) {
// Setup MQTT connection, subscribe to temp topic
client.setCallback(mqtt_callback);
client.subscribe(mqtt_temp_topic.c_str());
}
void mqtt_loop(PubSubClient& client) {
if (!client.connected()) {
// reconnect logic here
}
client.loop();
}
void mqtt_publish_state(PubSubClient& client, ThermostatMode mode, float targetTemp, bool heating) {
StaticJsonDocument<128> doc;
doc["mode"] = mode;
doc["target"] = targetTemp;
doc["heating"] = heating;
char buf[128];
size_t n = serializeJson(doc, buf);
client.publish(("home/thermostat/" + mqtt_device_id + "/state").c_str(), buf, n);
}
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
// Handle incoming MQTT messages (e.g., set mode, set preset, etc.)
}