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
tzapu/WiFiManager
bblanchon/ArduinoJson
ESPAsyncWebServer
ESPAsyncTCP
me-no-dev/ESPAsyncWebServer

View File

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