Browse Source

v0.2.1
* added second reduction mode with different set temperature
* MQTT reconnect now tries again every 5 min after 10 fails, finally restarts MCU on 20 unsuccessful retries

FloKra 6 years ago
parent
commit
d21fa4b40d

+ 4 - 0
CHANGELOG.md

@@ -1,4 +1,8 @@
 # WiFiThermostat - Changelog
+## 0.2.1
+* added second reduction mode with different set temperature
+* MQTT reconnect now tries again every 5 min after 10 fails, finally restarts MCU on 20 unsuccessful retries
+
 ## 0.2.0
 * improved MQTT reconnection management with heartbeat and force-reconnect
 * improved MQTT callback function

BIN
bin/WiFiThermostat.ino.d1_mini.20180228.bin


+ 12 - 2
src/WiFiThermostat/Display.ino

@@ -139,7 +139,12 @@ void updateDisplay() {
     else if ( heatingMode == 2 ) { // night/reduction mode
       lcd.print(" ");
       lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
+      lcd.print("1");
+    }
+    else if ( heatingMode == 3 ) { // night/reduction mode
       lcd.print(" ");
+      lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
+      lcd.print("2");
     }
   }
   else lcd.print("   "); // mode is heating off
@@ -149,6 +154,7 @@ void updateDisplay() {
   float curr_setTemp;
   if (heatingMode == 1) curr_setTemp = setTemp;
   else if (heatingMode == 2) curr_setTemp = setTempLow;
+  else if (heatingMode == 3) curr_setTemp = setTempLow2;
   char currSetTemp_chararr[6];
   dtostrf(curr_setTemp, 5, 1, currSetTemp_chararr );
 
@@ -175,7 +181,7 @@ void updateDisplay() {
     lcd.print(" ");
     if (turnHeatingOn) {
       //         1234567
-      lcd.print("heizen ");
+      lcd.print(" heizen");
     }
     else if ( heatingMode == 1 ) { // day/normal mode
       //         1234567
@@ -183,7 +189,11 @@ void updateDisplay() {
     }
     else if ( heatingMode == 2 ) { // night/reduction mode
       //         1234567
-      lcd.print("Absenk.");
+      lcd.print(" Abs. 1");
+    }
+    else if ( heatingMode == 3 ) { // night/reduction mode
+      //         1234567
+      lcd.print(" Abs. 2");
     }
     else lcd.print("        ");
   }

+ 3 - 1
src/WiFiThermostat/WiFiThermostat.ino

@@ -7,7 +7,7 @@
 #define SPIFFS_USE_MAGIC
 
 #define FIRMWARE_NAME "WiFiThermostat"
-#define VERSION "0.2.0"
+#define VERSION "0.2.1"
 
 
 
@@ -43,6 +43,7 @@
 #define DEFAULT_SETTEMP_MIN 16.0         // minimal temperature that can be set
 #define DEFAULT_SETTEMP_MAX 25.0         // maximal temperature that can be set
 #define DEFAULT_SETTEMP_LOW 18.0         // set temperature in night/low mode
+#define DEFAULT_SETTEMP_LOW2 20.0         // set temperature in night/low mode
 #define DEFAULT_HYSTERESIS 0.1           // hysteresis, normally 0.1 - 0.5
 #define SETTEMP_DECREASE_VALUE 0.0       // decreases the set temp to overcome further temperature rise when the heating is already switched off
 #define TEMPSENSOR_CORRECTION_VALUE 0.0  // correction value for temperature sensor reading
@@ -153,6 +154,7 @@ int heatingMinOffTime = DEFAULT_HEATING_MIN_OFFTIME; // minimal time the heating
 float setTempMin = DEFAULT_SETTEMP_MIN;           // minimal temperature that can be set
 float setTempMax = DEFAULT_SETTEMP_MAX;           // maximal temperature that can be set
 float setTempLow = DEFAULT_SETTEMP_LOW;           // set temperature in night/low mode
+float setTempLow2 = DEFAULT_SETTEMP_LOW2;           // set temperature in night/low mode
 float hysteresis = DEFAULT_HYSTERESIS;            // hysteresis, normally 0.1 - 0.5
 float setTempDecreaseVal = SETTEMP_DECREASE_VALUE;    // decreases the set temp to overcome further temperature rise when the heating is already switched off
 float tempCorrVal = TEMPSENSOR_CORRECTION_VALUE;  // correction value for temperature sensor reading

+ 32 - 12
src/WiFiThermostat/config.ino

@@ -27,8 +27,18 @@ bool setConfig(char* param, char* value) {
 #endif
     setTempLowTo(valueFloat);
   }
+  else if ( strcmp(param, "tempLow2") == 0 ) {
+    float valueFloat = round(atof(value) * 2.0) / 2.0;
+#ifdef DEBUG_VERBOSE
+    Serial.print(valueFloat);
+#endif
+    setTempLow2To(valueFloat);
+  }
   else if ( strcmp(param, "mode") == 0 ) {
-    setHeatingmodeTo(atoi(value));
+    int val = atoi(value);
+    if (val >= 0 && val <= 3) {
+      setHeatingmodeTo(val);
+    }
   }
 
   //confdata
@@ -214,6 +224,12 @@ void getConfig(char* param) {
     sprintf(buf, "setTempLow: '%s'", buf2);
     sendStatus(buf);
   }
+  else if ( strcmp(param, "tempLow2") == 0 ) {
+    char buf2[11];
+    dtostrf(setTempLow2, 2, 1, buf2);
+    sprintf(buf, "setTempLow2: '%s'", buf2);
+    sendStatus(buf);
+  }
   else if ( strcmp(param, "mode") == 0 ) {
     sprintf(buf, "heatingMode: '%d'", heatingMode);
     sendStatus(buf);
@@ -458,6 +474,8 @@ void printConfig2() {
   Serial.println(setTempMax);
   Serial.print("tempLow: ");
   Serial.print(setTempLow);
+  Serial.print("tempLow2: ");
+  Serial.print(setTempLow2);
   Serial.print("tempDec: ");
   Serial.println(setTempDecreaseVal);
   Serial.print("hyst: ");
@@ -598,7 +616,7 @@ bool loadConfig2() {
       domoticzIdx_ThermostatMode = atoi(json["domIdxMode"] | "");
       domoticzIdx_TempHumSensor = atoi(json["domIdxTempHum"] | "");
       domoticzIdx_Heating = atoi(json["domIdxHeating"] | "");
-      
+
       domoticzIdx_PIR = atoi(json["domIdxPIR"] | "");
       strlcpy(outTemp_topic_in, json["outTempTop"] | "", 51);
       strlcpy(outHum_topic_in, json["outHumTop"] | "", 51);
@@ -613,6 +631,7 @@ bool loadConfig2() {
       setTempMin = atof(json["tempMin"] | "");
       setTempMax = atof(json["tempMax"] | "");
       setTempLow = atof(json["tempLow"] | "");
+      setTempLow2 = atof(json["tempLow2"] | "");
       setTempDecreaseVal = atof(json["tempDec"] | "");
       hysteresis = atof(json["hyst"] | "");
       tempCorrVal = atof(json["tempCorr"] | "");
@@ -623,7 +642,7 @@ bool loadConfig2() {
 
       if (atoi(json["PIRenDisp"] | "") == 1) PIR_enablesDisplay = true;
       else PIR_enablesDisplay = false;
-     
+
       Serial.println("Loaded config values:");
       printConfig2();
       return true;
@@ -685,15 +704,15 @@ bool saveConfig() { // safeConfig
   json["inTop"] = mqtt_topic_in;
   json["outTop"] = mqtt_topic_out;
 
-  if(mqtt_outRetain) json["outRet"] = 1;
+  if (mqtt_outRetain) json["outRet"] = 1;
   else json["outRet"] = 0;
-  
+
   json["willTop"] = mqtt_willTopic;
   json["willQos"] = mqtt_willQos;
-  
-  if(mqtt_willRetain) json["willRet"] = 1;
+
+  if (mqtt_willRetain) json["willRet"] = 1;
   else json["willRet"] = 0;
-  
+
   json["willMsg"] = mqtt_willMsg;
   json["domOutTop"] = domoticz_out_topic;
 
@@ -723,16 +742,17 @@ bool saveConfig2() { // safeConfig2
   json["outTempTop"] = outTemp_topic_in;
   json["outHumTop"] = outHum_topic_in;
 
-  if(autoSaveSetTemp) json["autoSaveTemp"] = 1;
+  if (autoSaveSetTemp) json["autoSaveTemp"] = 1;
   else json["autoSaveTemp"] = 0;
 
-  if(autoSaveHeatingMode) json["autoSaveMode"] = 1;
+  if (autoSaveHeatingMode) json["autoSaveMode"] = 1;
   else json["autoSaveMode"] = 0;
-  
+
   json["minOffTime"] = heatingMinOffTime;
   json["tempMin"] = setTempMin;
   json["tempMax"] = setTempMax;
   json["tempLow"] = setTempLow;
+  json["tempLow2"] = setTempLow2;
   json["tempDec"] = setTempDecreaseVal;
   json["hyst"] = hysteresis;
   json["tempCorr"] = tempCorrVal;
@@ -741,7 +761,7 @@ bool saveConfig2() { // safeConfig2
   json["dispInt"] = displayInterval;
   json["dispTout"] = displayTimeout;
 
-  if(PIR_enablesDisplay) json["PIRenDisp"] = 1;
+  if (PIR_enablesDisplay) json["PIRenDisp"] = 1;
   else json["PIRenDisp"] = 0;
 
   yield();

+ 5 - 0
src/WiFiThermostat/domoticz.ino

@@ -135,6 +135,11 @@ void parseDomoticzOut() {
           lastValueChange = 0; // force saving of values without delay
           checkValuesChanged();
         }
+        else if (strcmp(svalue, "30") == 0) {
+          setHeatingmodeTo(3);
+          lastValueChange = 0; // force saving of values without delay
+          checkValuesChanged();
+        }
       }
     }
   }

+ 9 - 2
src/WiFiThermostat/httpServer.ino

@@ -92,7 +92,11 @@ static const char httpRoot[] PROGMEM =
           }
           else if(data.mode == '2') {
         g('btn_onoff').value = textE;
-            g('mode').innerHTML = 'Reduction';
+            g('mode').innerHTML = 'Reduction 1';
+          }
+          else if(data.mode == '3') {
+        g('btn_onoff').value = textE;
+            g('mode').innerHTML = 'Reduction 2';
           }
           
           if(data.heating == '1') g('heating').innerHTML = 'active';
@@ -257,6 +261,7 @@ Min. Off-Time: <input type='number' name='minOffTime' id='minOffTime'/><br>
 Min. Temp: <input type='text' name='tempMin' id='tempMin'/><br>
 Max. Temp: <input type='text' name='tempMax' id='tempMax'/><br>
 Reduction Mode Temp: <input type='text' name='tempLow' id='tempLow'/><br>
+Reduction Mode 2 Temp: <input type='text' name='tempLow2' id='tempLow2'/><br>
 set temp decrease value: <input type='text' name='tempDec' id='tempDec'/><br>
 Hysteresis: <input type='text' name='hyst' id='hyst'/><br>
 Temp Correction.: <input type='text' name='tempCorr' id='tempCorr'/><br>
@@ -334,6 +339,7 @@ PIR enables Display: <input type='checkbox' name='PIRenDisp' id='PIRenDisp'/>
           g('tempMin').value = data.tempMin;
           g('tempMax').value = data.tempMax;
           g('tempLow').value = data.tempLow;
+          g('tempLow2').value = data.tempLow2;
           g('tempDec').value = data.tempDec;
           g('hyst').value = data.hyst;
           g('tempCorr').value = data.tempCorr;
@@ -489,7 +495,7 @@ void httpServerInit() {
           char bufVal[20];
           httpServer.arg("value").toCharArray(bufVal, 20);
           int valueInt = atoi(bufVal);
-          if(valueInt >= 0 && valueInt <= 2) setHeatingmodeTo(valueInt);
+          if(valueInt >= 0 && valueInt <= 3) setHeatingmodeTo(valueInt);
           httpServer.send (200, "text/plain", "OK");
         }
       }
@@ -600,6 +606,7 @@ void httpServerInit() {
       json["tempMin"] = setTempMin;
       json["tempMax"] = setTempMax;
       json["tempLow"] = setTempLow;
+      json["tempLow2"] = setTempLow2;
       json["tempDec"] = setTempDecreaseVal;
       json["hyst"] = hysteresis;
       json["tempCorr"] = tempCorrVal;

+ 11 - 4
src/WiFiThermostat/mqtt.ino

@@ -201,7 +201,13 @@ void mqttHandleConnection() {
     if (doReconnect) {
       unsigned int mqttReconnectAttemptDelay;
       if (mqttReconnectAttempts < 3) mqttReconnectAttemptDelay = 15000; // if this is the 1-3rd attempt, try again in 15s
-      else mqttReconnectAttemptDelay = 60000; // if more than 3 attempts failed, try again in 1 min
+      else if (mqttReconnectAttempts < 10) mqttReconnectAttemptDelay = 60000; // if more than 3 attempts failed, try again every min
+      else if (mqttReconnectAttempts < 20) mqttReconnectAttemptDelay = 300000; // if more than 10 attempts failed, try again every 5 min
+      else if (mqttReconnectAttempts >= 20) {
+        // if more than 20 attempts failed, restart the ESP
+        delay(100);
+        ESP.restart();
+      }
 
       if ((millis() - mqttLastReconnectAttempt) > mqttReconnectAttemptDelay) {
         mqttLastReconnectAttempt = millis();
@@ -241,6 +247,7 @@ void publishCurrentThermostatValues() {
   float curr_setTemp;
   if (heatingMode == 1) curr_setTemp = setTemp;
   else if (heatingMode == 2) curr_setTemp = setTempLow;
+  else if (heatingMode == 3) curr_setTemp = setTempLow2;
 
   char setTemp_chararr[6];
   char currSetTemp_chararr[6];
@@ -265,20 +272,20 @@ void publishCurrentThermostatValues() {
   sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "currSetTemp");
   mqttclient.publish(tmp_topic_out, currSetTemp_chararr);
   yield();
-  
+
   sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "heatingMode");
   char heatingMode_chararr[3];
   sprintf(heatingMode_chararr, "%d", heatingMode);
   mqttclient.publish(tmp_topic_out, heatingMode_chararr);
   yield();
-  
+
   char turnHeatingOn_char[5];
   if (turnHeatingOn) strcpy(turnHeatingOn_char, "on");
   else strcpy(turnHeatingOn_char, "off");
   sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "heating");
   mqttclient.publish(tmp_topic_out, turnHeatingOn_char);
   yield();
-  
+
   char buf[101];
   sprintf(buf, "%d", heatingOnTime);
   sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "heatingOnTime");

+ 32 - 0
src/WiFiThermostat/thermostat.ino

@@ -53,6 +53,9 @@ void thermostat() {
   else if (heatingMode == 2) { // heating of - night/reduction mode
     curr_setTemp = setTempLow;
   }
+  else if (heatingMode == 3) { // heating of - night/reduction mode
+    curr_setTemp = setTempLow2;
+  }
 
   char tmp_topic_out[50];
   if (heatingMode > 0 && turnHeatingOn) {
@@ -143,6 +146,11 @@ void toggleHeatingMode() {
       heatingModeAlreadySaved = false;
     }
     else if (heatingMode == 2) {
+      heatingMode = 3;
+      lastValueChange = millis();
+      heatingModeAlreadySaved = false;
+    }
+    else if (heatingMode == 3) {
       heatingMode = 1;
       lastValueChange = millis();
       heatingModeAlreadySaved = false;
@@ -232,6 +240,26 @@ void setTempLowTo(float setTo) {
   }
 }
 
+void setTempLow2To(float setTo) {
+  bool changes = false;
+  if (setTo >= setTempLowMin && setTo <= setTempLowMax) {
+    setTempLow2 = setTo;
+    changes = true;
+  }
+  else if (setTo > setTempLowMax) {
+    setTempLow2 = setTempLowMax;
+    changes = true;
+  }
+  else if (setTo < setTempLowMin) {
+    setTempLow2 = setTempLowMin;
+    changes = true;
+  }
+  if (changes) {
+    updateDisplay();
+    publishCurrentThermostatValues();
+  }
+}
+
 void setHeatingmodeTo(byte setTo) {
   bool changes = false;
   switch (setTo) {
@@ -247,6 +275,10 @@ void setHeatingmodeTo(byte setTo) {
       heatingMode = 2;
       changes = true;
       break;
+    case 3:
+      heatingMode = 3;
+      changes = true;
+      break;
   }
   if (changes) {
     lastValueChange = millis();