This commit is contained in:
2026-03-12 11:17:37 +01:00
parent 7a7d33864c
commit 772726fa21
2 changed files with 38 additions and 36 deletions

View File

@@ -9,5 +9,4 @@ lib_deps =
knolleary/PubSubClient knolleary/PubSubClient
tzapu/WiFiManager tzapu/WiFiManager
bblanchon/ArduinoJson bblanchon/ArduinoJson
ESPAsyncWebServer me-no-dev/ESPAsyncWebServer
ESPAsyncTCP

View File

@@ -18,47 +18,50 @@ float currentTemp = 0.0;
*/ */
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
delay(10000);
// Retrieve config from EEPROM, connect to WiFi and MQTT, and set up thermostat presets // Retrieve config from EEPROM, connect to WiFi and MQTT, and set up thermostat presets
load_config(); // load_config();
// Debug: print current config and actions // Debug: print current config and actions
Serial.println("--- Thermostat Unit Startup ---"); Serial.println("Thermostat Unit Startup - Version 1.0");
Serial.print("WiFi SSID: "); Serial.println(wifi_ssid); // Serial.print("WiFi SSID: "); Serial.println(wifi_ssid);
Serial.print("MQTT Server: "); Serial.println(mqtt_server); // Serial.print("MQTT Server: "); Serial.println(mqtt_server);
Serial.print("MQTT Port: "); Serial.println(mqtt_port); // Serial.print("MQTT Port: "); Serial.println(mqtt_port);
Serial.print("MQTT User: "); Serial.println(mqtt_user); // Serial.print("MQTT User: "); Serial.println(mqtt_user);
Serial.print("MQTT Device ID: "); Serial.println(mqtt_device_id); // Serial.print("MQTT Device ID: "); Serial.println(mqtt_device_id);
Serial.print("MQTT Temp Topic: "); Serial.println(mqtt_temp_topic); // Serial.print("MQTT Temp Topic: "); Serial.println(mqtt_temp_topic);
Serial.print("Temp Sensor ID: "); Serial.println(temp_sensor_id); // Serial.print("Temp Sensor ID: "); Serial.println(temp_sensor_id);
Serial.print("Preset Confort: "); Serial.println(preset_confort); // Serial.print("Preset Confort: "); Serial.println(preset_confort);
Serial.print("Preset Eco: "); Serial.println(preset_eco); // Serial.print("Preset Eco: "); Serial.println(preset_eco);
Serial.print("Preset Boost: "); Serial.println(preset_boost); // Serial.print("Preset Boost: "); Serial.println(preset_boost);
Serial.print("Preset Hors Gel: "); Serial.println(preset_hors_gel); // Serial.print("Preset Hors Gel: "); Serial.println(preset_hors_gel);
Serial.println("Connecting to WiFi..."); Serial.println("Connecting to WiFi...");
delay(5000);
// setup wifi and mqtt, and load presets into thermostat // setup wifi and mqtt, and load presets into thermostat
setup_web_config(); // setup_web_config();
WiFi.begin(wifi_ssid.c_str(), wifi_pass.c_str()); WiFi.begin(wifi_ssid.c_str(), wifi_pass.c_str());
Serial.println("Connecting to MQTT..."); // Serial.println("Connecting to MQTT...");
mqttClient.setServer(mqtt_server.c_str(), mqtt_port); // mqttClient.setServer(mqtt_server.c_str(), mqtt_port);
setup_mqtt(mqttClient); // setup_mqtt(mqttClient);
load_presets(); // load_presets();
thermostat.setPresetTemp(MODE_CONFORT, preset_confort); // thermostat.setPresetTemp(MODE_CONFORT, preset_confort);
thermostat.setPresetTemp(MODE_ECO, preset_eco); // thermostat.setPresetTemp(MODE_ECO, preset_eco);
thermostat.setPresetTemp(MODE_BOOST, preset_boost); // thermostat.setPresetTemp(MODE_BOOST, preset_boost);
thermostat.setPresetTemp(MODE_HORS_GEL, preset_hors_gel); // thermostat.setPresetTemp(MODE_HORS_GEL, preset_hors_gel);
// Retreive current temp from MQTT (if available) and set initial mode to lastvalue (stored in EEPROM) or MODE_OFF if not available // // Retreive current temp from MQTT (if available) and set initial mode to lastvalue (stored in EEPROM) or MODE_OFF if not available
thermostat.setMode(MODE_OFF); // thermostat.setMode(MODE_OFF);
} }
void loop() { void loop() {
handle_web_config(); Serial.println("Entering main loop...");
// Ask Mqtt to process incoming messages and maintain connection // handle_web_config();
mqtt_loop(mqttClient); // // Ask Mqtt to process incoming messages and maintain connection
// Update thermostat state based on current temp and publish state to MQTT // mqtt_loop(mqttClient);
thermostat.update(currentTemp); // // Update thermostat state based on current temp and publish state to MQTT
// Publish state to MQTT every second (or on state change, if you want to optimize) // thermostat.update(currentTemp);
mqtt_publish_state(mqttClient, thermostat.getMode(), thermostat.getTargetTemp(), thermostat.isHeating()); // // Publish state to MQTT every second (or on state change, if you want to optimize)
// Delay to avoid flooding MQTT with messages. Adjust as needed for your use case (e.g., publish on state change // mqtt_publish_state(mqttClient, thermostat.getMode(), thermostat.getTargetTemp(), thermostat.isHeating());
// instead of every loop). // // Delay to avoid flooding MQTT with messages. Adjust as needed for your use case (e.g., publish on state change
delay(1000); // // instead of every loop).
delay(5000);
} }