Browse Source

2023-03-09
- Sensors_OneWire: ignore value 85°C if last value <80 or >90 (filter 85 as it is used as error code)
- Sensors_OneWire: increase precision to 12 bit
- Sensors_OneWire: float values in web interface and MQTT
- Sensors: fix bug not publishing OneWire values when DHT sensor is disabled
- WebIF - Heatcontrol: hide Heat Curve and DHT sensor if disabled

FloKra 1 year ago
parent
commit
d5d331e05b

+ 18 - 0
changelog.txt

@@ -1,3 +1,21 @@
+2023-03-09
+	- Sensors_OneWire: ignore value 85°C if last value <80 or >90 (filter 85 as it is used as error code)
+	- Sensors_OneWire: increase precision to 12 bit
+	- Sensors_OneWire: float values in web interface and MQTT
+	- Sensors: fix bug not publishing OneWire values when DHT sensor is disabled
+	- WebIF - Heatcontrol: hide Heat Curve and DHT sensor if disabled
+	
+2023-03-07
+	- Sensors_DHT: changed log levels
+	- Sensors_DHT: add option to disable DHT sensor
+	- Sensors_DHT: make more settings pre-compile configurable
+	- Scheduler: use millis for 100ms/1s/1m each, not nested any more
+	
+2023-03-06
+	- fixed bug in config_set.ino - sensor configuration items were only available when compiled as variant thermostat
+	- fixed web interface - conf UI sensors and heat control
+	- moved one wire pre compile config to settings.h
+
 2023-02-17 - 2023-03-03
 	- huge code review, many changes to improve stability
 	- basic multilanguage support (pre-compile option)

+ 1 - 1
platformio.ini

@@ -95,7 +95,7 @@ build_flags = ${env.build_flags} -DFIRMWARE_VARIANT_HEATCONTROL
 #lib_extra_dirs          =
 upload_protocol = espota
 #upload_port = 10.1.5.154
-upload_port = 10.1.5.154
+upload_port = 10.1.5.169
 upload_flags =
   --port=8266
 #upload_speed = 921600

+ 2 - 2
src/ESPIoTBase.ino

@@ -441,7 +441,7 @@ void setup()
   #endif
     
   #ifdef ENABLE_SENSOR_DHT22
-    DHT_measureTempHum();
+    if (confSens.DHT_enable) DHT_measureTempHum();
   #endif
 
   #ifdef FIRMWARE_VARIANT_THERMOSTAT
@@ -458,7 +458,7 @@ void setup()
 
 void loop()
 {
-  checkMillis();
+  scheduler_checkMillis();
 
   persWM.handleWiFi(); // in non-blocking mode, handleWiFi must be called in the main loop
   yield();

+ 16 - 1
src/config_set.ino

@@ -1158,6 +1158,21 @@ void setConfig(char *param, char *value)
   }
 
   #ifdef ENABLE_SENSOR_DHT22
+    else if (strcmp(param, "dht_enable") == 0)
+    {
+      bool tmpval;
+      if (atoi(value) == 1)
+        tmpval = true;
+      else
+        tmpval = false;
+
+      if (tmpval != confSens.DHT_enable)
+      {
+        confSens.DHT_enable = tmpval;
+        confSens_wasChanged = true;
+      }
+    }
+
     else if (strcmp(param, "dht_tempcorr") == 0)
     {
       float valueFloat = atof(value);
@@ -1170,7 +1185,7 @@ void setConfig(char *param, char *value)
         }
       }
     }
-  
+
     else if (strcmp(param, "dht_humcorr") == 0)
     {
       int valueInt = atoi(value);

+ 11 - 5
src/globalVars.h

@@ -42,10 +42,12 @@ int sensor_DHT_readRetries = 2;
 unsigned long sensor_DHT_lastUpdate = 0;    // last update time of DHT reading
 
 // OneWire Sensors
-int8_t owTemp_feed, owTemp_return, owTemp_out;
+float owTemp_feed;
+float owTemp_return;
+float owTemp_out;
 
 
-// 
+// Outside Temp/Hum via MQTT
 float outTemp;                      // outside temp (via MQTT if enabled and in-topic configured)
 uint16_t outHum;                    // outside temp (via MQTT if enabled and in-topic configured)
 unsigned long outTempHumLastUpdate; // last reading from out temp/hum source
@@ -91,9 +93,13 @@ unsigned long lastConfigChange;
 bool lastConfigChangeNoteAlreadyDone = false;
 
 
-unsigned long lastRun = 0;
-uint16_t count100ms = 0;
-uint16_t countSeconds = 0;
+unsigned long lastMillis_100ms = 0;
+unsigned long lastMillis_1s = 0;
+unsigned long lastMillis_1m = 0;
+
+//uint16_t count100ms = 0;
+//uint16_t countSeconds = 0;
+
 uint16_t countMeasureInterval = 0;
 
 unsigned long mqttLastReconnectAttempt = 0;

+ 1 - 0
src/globalVars_conf.h

@@ -145,6 +145,7 @@ struct confDataSens
   float DHT_tempCorrVal;          // correction value for
                               // temperature sensor reading
   int DHT_humCorrVal;             // correction value for humidity sensor reading
+  bool DHT_enable;
   
 } confSens;
 bool confSens_wasChanged = false;

+ 4 - 3
src/html_confSens.h

@@ -5,7 +5,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
     if (!xhttp) {   
     reqTime = 0;
     reqFin = false;
-    //updCbxVal(g('togTHdisp'));
+    updCbxVal(g('DHT_enable'));
     xhttp = new XMLHttpRequest();
     xhttp.timeout = 1000;
     xhttp.overrideMimeType('application/json');
@@ -20,7 +20,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
         g('measInt').value = data.measInt;
         g('DHT_tempCorr').value = data.DHT_tempCorr;
         g('DHT_humCorr').value = data.DHT_tempCorr;
-        //setCbx(g('togTHdisp'), data.togTHdisp);
+        setCbx(g('DHT_enable'), data.DHT_enable);
         xhttp = null;
         reqFin = true;
        }
@@ -36,7 +36,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
   }
   //transmit();
   function saveConf() {
-    //updCbxVal(g('togTHdisp'));
+    updCbxVal(g('DHT_enable'));
     g('frmConf').submit();
   }
   function init() {
@@ -85,6 +85,7 @@ static const char html_confSens_dht[] PROGMEM = R"=====(
 <div></div><br>
 <fieldset>
 <legend>DHT Temperature Sensors</legend>
+<p><b>Enable DHT Sensor</b>&nbsp;<input type='checkbox' name='DHT_enable' id='DHT_enable'></p>
 <p><b>Measured Temp Correction [°C] *</b><br><input type='text' name='DHT_tempCorr' id='DHT_tempCorr'></p>
 <p><b>Measured Hum Correction [%] *</b><br><input type='text' name='DHT_humCorr' id='DHT_humCorr'></p>
 <p class='n'>* added to the measured values. <br>Can be negative and/or fractions. <br>Use if measurements deviate from a calibrated sensor.</p><br>

+ 4 - 3
src/html_confSens_DE.h

@@ -5,7 +5,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
     if (!xhttp) {   
     reqTime = 0;
     reqFin = false;
-    //updCbxVal(g('togTHdisp'));
+    updCbxVal(g('DHT_enable'));
     xhttp = new XMLHttpRequest();
     xhttp.timeout = 1000;
     xhttp.overrideMimeType('application/json');
@@ -20,7 +20,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
         g('measInt').value = data.measInt;
         g('DHT_tempCorr').value = data.DHT_tempCorr;
         g('DHT_humCorr').value = data.DHT_humCorr;
-        //setCbx(g('togTHdisp'), data.togTHdisp);
+        setCbx(g('DHT_enable'), data.DHT_enable);
         xhttp = null;
         reqFin = true;
        }
@@ -36,7 +36,7 @@ static const char html_confSens_script[] PROGMEM = R"=====(
   }
   //transmit();
   function saveConf() {
-    //updCbxVal(g('togTHdisp'));
+    updCbxVal(g('DHT_enable'));
     g('frmConf').submit();
   }
   function init() {
@@ -85,6 +85,7 @@ static const char html_confSens_dht[] PROGMEM = R"=====(
 <div></div><br>
 <fieldset>
 <legend>DHT Temperatur- u. Luftfeuchtesensor</legend>
+<p><b>DHT-Sensor aktivieren</b>&nbsp;<input type='checkbox' name='DHT_enable' id='DHT_enable'></p>
 <p><b>Korrekturwert Temperatur [°C] *</b><br><input type='text' name='DHT_tempCorr' id='DHT_tempCorr'></p>
 <p><b>Korrekturwert Luftfeuchte [%] *</b><br><input type='text' name='DHT_humCorr' id='DHT_humCorr'></p>
 <p class='n'>* wird zum gemessenen Wert addiert. <br>

+ 32 - 15
src/html_main_heatcontrol_DE.h

@@ -63,16 +63,28 @@ static const char html_main_script[] PROGMEM = R"=====(
           if(data.cDisPump == '1') { g('cDisPump').innerHTML = 'AKTIV'; g('cDisPump').style = 'color:red;'; }
           else { g('cDisPump').innerHTML = 'INAKTIV'; g('cDisPump').style = 'color:black;'; }
 
-          if(data.tempFeed !== undefined) g('tempFeed').innerHTML = data.tempFeed + '&deg;';
-          if(data.tempReturn !== undefined) g('tempReturn').innerHTML = data.tempReturn + '&deg;';
-          if(data.tempOut !== undefined) g('tempOut').innerHTML = data.tempOut + '&deg;';
+          if(data.tempFeed !== undefined) g('tempFeed').innerHTML = data.tempFeed.toFixed(1) + '&deg;';
+          if(data.tempReturn !== undefined) g('tempReturn').innerHTML = data.tempReturn.toFixed(1) + '&deg;';
+          if(data.tempOut !== undefined) g('tempOut').innerHTML = data.tempOut.toFixed(1) + '&deg;';
           
-          if(data.currHeatC !== undefined) g('currHeatC').innerHTML = data.currHeatC + '&deg;';
-          if(data.currHeatCOff !== undefined) g('currHeatCOff').innerHTML = data.currHeatCOff + '&deg;';
-          if(data.currHeatCOn !== undefined) g('currHeatCOn').innerHTML = data.currHeatCOn + '&deg;';
-
-          if(data.temp !== undefined && data.hum !== undefined) g('currTempHum').innerHTML = data.temp.toFixed(1) + '&deg;&nbsp;&nbsp;&nbsp;' + data.hum.toFixed(0) + '%';
-          else if(data.temp !== undefined) g('currTempHum').innerHTML = data.temp.toFixed(1) + '&deg;';
+          if(data.useHeatC !== undefined) {
+            if(data.useHeatC) {
+                g('div_heatc').style = 'visibility: visible';
+                if(data.currHeatC !== undefined) g('currHeatC').innerHTML = data.currHeatC + '&deg;';
+                if(data.currHeatCOff !== undefined) g('currHeatCOff').innerHTML = data.currHeatCOff + '&deg;';
+                if(data.currHeatCOn !== undefined) g('currHeatCOn').innerHTML = data.currHeatCOn + '&deg;';
+              }
+          }
+          
+          if(data.temp !== undefined && data.hum !== undefined) {
+              g('div_sens_dht').style = 'visibility: visible';
+              g('currTempHum').innerHTML = data.temp.toFixed(1) + '&deg;&nbsp;&nbsp;&nbsp;' + data.hum.toFixed(0) + '%';
+            }
+          else if(data.temp !== undefined) {
+              g('div_sens_dht').style = 'visibility: visible';
+              g('currTempHum').innerHTML = data.temp.toFixed(1) + '&deg;';
+            }
+          else g('div_sens_dht').style = 'visibility: collapse';
           
           var APname;
           if(data.WiFiNum == 1) APname='Haupt-AP';
@@ -136,16 +148,16 @@ static const char html_main_body_app[] PROGMEM = R"=====(
 
 <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
 <tr><td>Testbetrieb </td><td><b><span id='statTest'></span></b></td></tr>
+</table>
 
-<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
-<tr><td>Heizkurve</td><td>&nbsp;</td></tr>
+<div id='div_heatc' style='visibility: collapse;'>
+<table style='width:100%'>
+<tr><td style='width:50%'>Heizkurve</td><td>&nbsp;</td></tr>
 <tr><td>&nbsp;&nbsp;Schwellwert Aus</td><td><b><span id='currHeatCOff'></span></b></td></tr>
 <tr><td>&nbsp;&nbsp;aktueller Sollwert</td><td><b><span id='currHeatC'></span></b></td></tr>
 <tr><td>&nbsp;&nbsp;Schwellwert Ein</td><td><b><span id='currHeatCOn'></span></b></td></tr>
-
-<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
-
 </table>
+</div>
 
 <div></div>
 <div></div>
@@ -161,8 +173,13 @@ static const char html_main_body_app[] PROGMEM = R"=====(
 <tr><td style='width:50%'>Heizung Vorlauf </td><td><b><span id='tempFeed'></span></td></tr>
 <tr><td>Heizung R&uuml;cklauf </td><td><b><span id='tempReturn'></span></td></tr>
 <tr><td>Au&szlig;en </td><td><b><span id='tempOut'></span></b></td></tr>
-<tr><td>Heizraum </td><td><b><span id='currTempHum'></span></td></tr>
 </table>
+<div id='div_sens_dht' style='padding:0px; visibility:collapse;'>
+<table style='width:100%'>
+<tr><td style='padding:0px; width:50%'>Heizraum </td><td><b><span id='currTempHum'></span></td></tr>
+</table>
+</div>
+
 )====="; // html_main_body_app
 
 #endif

+ 75 - 83
src/mqtt_out.ino

@@ -6,97 +6,89 @@ int currHum_lastPublished;
 
 void publishCurrentSensorValues(bool force = false)
 {
-  if (sensor_DHT_lastUpdate != 0 && (millis() - sensor_DHT_lastUpdate) < 120000)
-  { // ensure values are not too old
-    char _tmp_topic_out[50];
-    char _temp_chararr[6];
-    char _hum_chararr[4];
-
-    #ifdef ENABLE_SENSOR_DHT22
-      
-      dtostrf(sensor_DHT_currTemp, 1, 1, _temp_chararr);
-      sprintf(_hum_chararr, "%2i", sensor_DHT_currHum);
-  
-      // if (serialdebug)
-      // {
-      //   Serial.print(F("sensors: {"));
-      //   Serial.print("'temp':");
-      //   Serial.print(_temp_chararr);
-      // }
-  
-      if (force || sensor_DHT_currTemp != currTemp_lastPublished)
-      {
-        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp");
-        mqttclient.publish(_tmp_topic_out, _temp_chararr, confMqtt.mqtt_outRetain_sensors);
-        currTemp_lastPublished = sensor_DHT_currTemp;
-        yield();
-      }
-  
-      // if (serialdebug)
-      // {
-      //   Serial.print(F(",'hum':"));
-      //   Serial.print(sensor_DHT_currHum);
-      // }
-  
-      if (force || sensor_DHT_currHum != currHum_lastPublished)
-      {
-        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "hum");
-        mqttclient.publish(_tmp_topic_out, _hum_chararr, confMqtt.mqtt_outRetain_sensors);
-        yield();
-      }
-  
-      dtostrf(sensor_DHT_currTemp_raw, 1, 1, _temp_chararr);
-      sprintf(_hum_chararr, "%2i", sensor_DHT_currHum_raw);
+  char _tmp_topic_out[50];
+  char _temp_chararr[6];
+  char _hum_chararr[4];
   
-      // if (serialdebug)
-      // {
-      //   Serial.print(F(",'temp_raw':"));
-      //   Serial.print(_temp_chararr);
-      // }
-      snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_raw");
-      mqttclient.publish(_tmp_topic_out, _temp_chararr);
-      yield();
-      // if (serialdebug)
-      // {
-      //   Serial.print(F(",'hum_raw':"));
-      //   Serial.print(sensor_DHT_currHum_raw);
-      // }
-      snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "hum_raw");
-      mqttclient.publish(_tmp_topic_out, _hum_chararr);
-      yield();
-    #endif // ENABLE_SENSOR_DHT22
-
-
-
-    #ifdef ENABLE_SENSORS_ONEWIRE
-
-      if (owTemp_feed > -50) {
-        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_feed");
-        dtostrf(owTemp_feed, 1, 0, _temp_chararr);
+  #ifdef ENABLE_SENSOR_DHT22
+    if (confSens.DHT_enable && sensor_DHT_lastUpdate != 0 && (millis() - sensor_DHT_lastUpdate) < 120000)
+    { // ensure values are not too old    
+        dtostrf(sensor_DHT_currTemp, 1, 1, _temp_chararr);
+        sprintf(_hum_chararr, "%2i", sensor_DHT_currHum);
+
+        // if (serialdebug)
+        // {
+        //   Serial.print(F("sensors: {"));
+        //   Serial.print("'temp':");
+        //   Serial.print(_temp_chararr);
+        // }
+
+        if (force || sensor_DHT_currTemp != currTemp_lastPublished)
+        {
+          snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp");
+          mqttclient.publish(_tmp_topic_out, _temp_chararr, confMqtt.mqtt_outRetain_sensors);
+          currTemp_lastPublished = sensor_DHT_currTemp;
+          yield();
+        }
+
+        // if (serialdebug)
+        // {
+        //   Serial.print(F(",'hum':"));
+        //   Serial.print(sensor_DHT_currHum);
+        // }
+
+        if (force || sensor_DHT_currHum != currHum_lastPublished)
+        {
+          snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "hum");
+          mqttclient.publish(_tmp_topic_out, _hum_chararr, confMqtt.mqtt_outRetain_sensors);
+          yield();
+        }
+
+        dtostrf(sensor_DHT_currTemp_raw, 1, 1, _temp_chararr);
+        sprintf(_hum_chararr, "%2i", sensor_DHT_currHum_raw);
+
+        // if (serialdebug)
+        // {
+        //   Serial.print(F(",'temp_raw':"));
+        //   Serial.print(_temp_chararr);
+        // }
+        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_raw");
         mqttclient.publish(_tmp_topic_out, _temp_chararr);
         yield();
-      }
-
-      if (owTemp_return > -50) {
-        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_return");
-        dtostrf(owTemp_return, 1, 0, _temp_chararr);
-        mqttclient.publish(_tmp_topic_out, _temp_chararr);
+        // if (serialdebug)
+        // {
+        //   Serial.print(F(",'hum_raw':"));
+        //   Serial.print(sensor_DHT_currHum_raw);
+        // }
+        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "hum_raw");
+        mqttclient.publish(_tmp_topic_out, _hum_chararr);
         yield();
-      }
+    }
+  #endif // ENABLE_SENSOR_DHT22
 
-      if (owTemp_out > -50) {
-        snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_out");
-        dtostrf(owTemp_out, 1, 0, _temp_chararr);
-        mqttclient.publish(_tmp_topic_out, _temp_chararr);
-        yield();
-      }
 
-    #endif // ENABLE_SENSORS_ONEWIRE
+  #ifdef ENABLE_SENSORS_ONEWIRE
+    if (owTemp_feed > -50.0) {
+      snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_feed");
+      dtostrf(owTemp_feed, 1, 1, _temp_chararr);
+      mqttclient.publish(_tmp_topic_out, _temp_chararr);
+      yield();
+    }
 
+    if (owTemp_return > -50.0) {
+      snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_return");
+      dtostrf(owTemp_return, 1, 1, _temp_chararr);
+      mqttclient.publish(_tmp_topic_out, _temp_chararr);
+      yield();
+    }
 
-    // if (serialdebug)
-    //   Serial.println("}");
-  }
+    if (owTemp_out > -50.0) {
+      snprintf(_tmp_topic_out, 50, "%s/%s", confMqtt.mqtt_topic_out, "temp_out");
+      dtostrf(owTemp_out, 1, 1, _temp_chararr);
+      mqttclient.publish(_tmp_topic_out, _temp_chararr);
+      yield();
+    }
+  #endif // ENABLE_SENSORS_ONEWIRE
 }
 
 void publishCurrentPIRValue()

+ 24 - 28
src/scheduler.ino

@@ -1,35 +1,31 @@
-
-void checkMillis()
+void scheduler_checkMillis()
 {
-  if ((millis() - lastRun) >= 100)
+  if ((millis() - lastMillis_100ms) >= 100)
   {
-    lastRun = millis();
-    every100ms();
+    lastMillis_100ms = millis();
+    scheduler_every100ms();
   }
-}
 
-void every100ms()
-{
-  if (count100ms < 10)
-    count100ms++;
-  else
+  if ((millis() - lastMillis_1s) >= 1000)
   {
-    count100ms = 0;
-    everySecond();
+    lastMillis_1s = millis();
+    scheduler_everySecond();
   }
-  //checkSaveConfigTriggered();
-}
 
-void everySecond()
-{
-  if (countSeconds < 60)
-    countSeconds++;
-  else
+  if ((millis() - lastMillis_1m) >= 60000)
   {
-    countSeconds = 0;
-    everyMinute();
+    lastMillis_1m = millis();
+    scheduler_everyMinute();
   }
+}
 
+void scheduler_every100ms()
+{
+  //checkSaveConfigTriggered();
+}
+
+void scheduler_everySecond()
+{
   conf_confChangedLogNote(false); // only outputs once if false and only if config is not saved
 
   //webSocket.sendTXT(num, "Test\n");
@@ -66,7 +62,7 @@ void everySecond()
     #endif
     
     #ifdef ENABLE_SENSOR_DHT22
-      DHT_measureTempHum();
+      if (confSens.DHT_enable) DHT_measureTempHum();
     #endif
     
     #ifdef FIRMWARE_VARIANT_THERMOSTAT
@@ -142,12 +138,12 @@ void everySecond()
     heatcontrol_mainFunction();
   #endif
 
-} // everySecond()
+} // scheduler_everySecond()
 
 
 
 
-void everyMinute()
+void scheduler_everyMinute()
 {
   #ifdef ENABLE_FEATURE_NTP_TIME
     if (confTime.ntpEnable) {
@@ -197,7 +193,7 @@ void everyMinute()
     else {
       outPubInterval_states_count++;
       #ifdef FIRMWARE_VARIANT_THERMOSTAT
-      thermostat_publishCurrentValues(false); // false publishes only changed values
+        thermostat_publishCurrentValues(false); // false publishes only changed values
       #endif
     }
 
@@ -210,6 +206,6 @@ void everyMinute()
       publishCurrentSensorValues(false); // false publishes only changed values
     }
 
-    DHT_logCurrentData();
+    if (confSens.DHT_enable) DHT_logCurrentData();
   }
-} // everyMinute()
+} // scheduler_everyMinute()

+ 24 - 29
src/sensor_dht.ino

@@ -1,80 +1,75 @@
 #ifdef ENABLE_SENSOR_DHT22
 
-void DHT_readTemp() {
-  //delay(DHTreadDelay);
-  sensor_DHT_tmpTemp = dht.readTemperature();  // Read temperature as Celsius (the default)
-}
-void DHT_readHum() {
-  //delay(DHTreadDelay);
-  sensor_DHT_tmpHum = dht.readHumidity();
-}
+#define SENSOR_DHT_MIN_VALUE -25.0
+#define SENSOR_DHT_MAX_VALUE 50.0
+#define SENSOR_DHT_MAXDIFFFROMLASTTEMP 2.0
+#define SENSOR_DHT_FILTER_FACTOR 10
+
 
 void DHT_logCurrentData() {
   sprintf_P(logBuf, "DHT: temp=%2.1f, hum=%u, tempRaw=%2.1f, humRaw=%u", sensor_DHT_currTemp, sensor_DHT_currHum, sensor_DHT_currTemp_raw, sensor_DHT_currHum_raw);
   sendLog(logBuf, LOGLEVEL_INFO);
 }
 
+
 void DHT_measureTempHum() {
 
+  // try reading temperature
   for (int _i = 0; _i < sensor_DHT_readRetries; _i++) {
-    DHT_readTemp();
+    sensor_DHT_tmpTemp = dht.readTemperature();  // read temp in celsius
     if (!isnan(sensor_DHT_tmpTemp)) {
       sendLog(F("DHT: reading Temp OK"), LOGLEVEL_VERBOSE);
       _i = sensor_DHT_readRetries;
     }
     else {
-      sendLog(F("DHT: reading Temp failed - retrying.."), LOGLEVEL_INFO);
+      sendLog(F("DHT: reading Temp failed"), LOGLEVEL_DEBUG);
     }
   }
-//
+
+  // try reading humidity
   for (int _i = 0; _i < sensor_DHT_readRetries; _i++) {
-    DHT_readHum();
+    sensor_DHT_tmpHum = dht.readHumidity();
     if (!isnan(sensor_DHT_tmpHum)) {
       sendLog(F("DHT: reading Hum OK"), LOGLEVEL_VERBOSE);
       _i = sensor_DHT_readRetries;
     }
     else {
-      sendLog(F("DHT: reading Hum failed - retrying.."), LOGLEVEL_INFO);
+      sendLog(F("DHT: reading Hum failed"), LOGLEVEL_DEBUG);
     }
   }
 
   // Check if any reads failed
   if (isnan(sensor_DHT_tmpHum) || isnan(sensor_DHT_tmpTemp)) {
-    //Serial.println("Failed to read from DHT sensor!");
     sendLog(F("DHT: Failed to read sensor."), LOGLEVEL_ERROR);
   }
   else {
     sensor_DHT_tmpTemp = sensor_DHT_tmpTemp + confSens.DHT_tempCorrVal;
     sensor_DHT_tmpHum = round(sensor_DHT_tmpHum) + confSens.DHT_humCorrVal;
+    
     int _tmpHumInt = sensor_DHT_tmpHum;
-    if (sensor_DHT_tmpTemp < 50.0 && sensor_DHT_tmpTemp > -20.0) {
+
+    if (sensor_DHT_tmpTemp <= SENSOR_DHT_MAX_VALUE && sensor_DHT_tmpTemp >= SENSOR_DHT_MIN_VALUE) {
       // measurement is in range
       sensor_DHT_currTemp_raw = sensor_DHT_tmpTemp;
       sensor_DHT_currHum_raw = _tmpHumInt;
 
-      if ( sensor_DHT_lastUpdate > 0 && sensor_DHT_tmpTemp <= ( sensor_DHT_currTemp + 2.0 ) && sensor_DHT_tmpTemp >= ( sensor_DHT_currTemp - 2.0 ) ) {
-        // temp has already been measured - only accept new measurement if it does not differ much from the last value
-        //Temp = (Temp * (FilterFaktor -1) + AktuellerMesswert) / FilterFaktor;
-        //temperature = tmpTemp;
-        sensor_DHT_currTemp = (sensor_DHT_currTemp * 9 + sensor_DHT_tmpTemp) / 10; // filter
-        sensor_DHT_currHum = (sensor_DHT_currHum * 9 + _tmpHumInt) / 10; // filter
+      if ( sensor_DHT_lastUpdate > 0 && sensor_DHT_tmpTemp <= ( sensor_DHT_currTemp + SENSOR_DHT_MAXDIFFFROMLASTTEMP ) && sensor_DHT_tmpTemp >= ( sensor_DHT_currTemp - SENSOR_DHT_MAXDIFFFROMLASTTEMP ) ) {
+        // temp has already been measured
+        // only accept new measurement if it does not differ too much from the last value
+        // then apply filter:
+        // Temp = (Temp * (FilterFactor -1) + currentMeasurement) / FilterFactor;
+        sensor_DHT_currTemp = (sensor_DHT_currTemp * (SENSOR_DHT_FILTER_FACTOR - 1) + sensor_DHT_tmpTemp) / SENSOR_DHT_FILTER_FACTOR; // filter
+        sensor_DHT_currHum = (sensor_DHT_currHum * (SENSOR_DHT_FILTER_FACTOR - 1) + _tmpHumInt) / SENSOR_DHT_FILTER_FACTOR; // filter
         sensor_DHT_lastUpdate = millis();
       }
       else if ( sensor_DHT_lastUpdate == 0 || (millis() - sensor_DHT_lastUpdate) > sensors_maxMeasurementAge ) {
-        // this is the first measurement or the last one is older than 5m - then accept this measurement
+        // this is the first measurement or the last one is older than 5m - always accept measurement 
         sensor_DHT_currTemp = sensor_DHT_tmpTemp + confSens.DHT_tempCorrVal;
         sensor_DHT_currHum = _tmpHumInt + confSens.DHT_humCorrVal;
         sensor_DHT_lastUpdate = millis();
 
       }
       // skip in all other cases
-
-      //#ifdef DEBUG_VERBOSE
-      //      Serial.print("lastTempUpdate: ");
-      //      long lastTempUpdateDelta = millis() - lastTempUpdate;
-      //      Serial.print(lastTempUpdateDelta / 1000);
-      //      Serial.println("s ago");
-      //#endif
     }
   }
 }

+ 46 - 13
src/sensors_oneWire.ino

@@ -1,6 +1,6 @@
 #ifdef ENABLE_SENSORS_ONEWIRE
 
-#define DALLAS_TEMPERATURE_PRECISION 9
+#define DALLAS_TEMPERATURE_PRECISION 12
 
 void oneWireSensors_setup() {
     oneWireSensors.begin();
@@ -141,10 +141,12 @@ void oneWireSensors_setup() {
 //   Serial.println();
 // }
 
+//float owTemp_lastValue_feed, owTemp_lastValue_return, owTemp_lastValue_out;
+
 void oneWireSensors_getData() 
 {    
     snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: reading temperatures");
-    sendLog(logBuf, LOGLEVEL_INFO);
+    sendLog(logBuf, LOGLEVEL_DEBUG);
 
     oneWireSensors.requestTemperatures();
 
@@ -165,9 +167,19 @@ void oneWireSensors_getData()
             owTemp_feed = -127;
         }
         else {
-            owTemp_feed = (int)tempC;
-            snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'FEED' = %d", owTemp_feed);
-            sendLog(logBuf, LOGLEVEL_INFO);
+            // filter value 85 as it is used as an error code by the lib
+            // if the last measured value was >=80 and <=90 assume the value is OK
+            bool _valueOK = false;
+            if ((int)tempC == 85) {
+                if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
+            }
+            else _valueOK = true;
+
+            if (_valueOK) {
+                owTemp_feed = tempC;
+                snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'FEED' = %1.1f", owTemp_feed);
+                sendLog(logBuf, LOGLEVEL_INFO);
+            }
         }
     }
     else {
@@ -185,9 +197,19 @@ void oneWireSensors_getData()
             owTemp_return = -127;
         }
         else {
-            owTemp_return = (int)tempC;
-            snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'RETURN' = %d", owTemp_return);
-            sendLog(logBuf, LOGLEVEL_INFO);
+            // filter value 85 as it is used as an error code by the lib
+            // if the last measured value was >=80 and <=90 assume the value is OK
+            bool _valueOK = false;
+            if ((int)tempC == 85) {
+                if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
+            }
+            else _valueOK = true;
+
+            if (_valueOK) {
+                owTemp_return = tempC;
+                snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'RETURN' = %1.1f", owTemp_return);
+                sendLog(logBuf, LOGLEVEL_INFO);
+            }
         }
     }
     else {
@@ -205,9 +227,19 @@ void oneWireSensors_getData()
             owTemp_out = -127;
         }
         else {
-            owTemp_out = (int)tempC;
-            snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'OUT' = %d", owTemp_out);
-            sendLog(logBuf, LOGLEVEL_INFO);
+            // filter value 85 as it is used as an error code by the lib
+            // if the last measured value was >=80 and <=90 assume the value is OK
+            bool _valueOK = false;
+            if ((int)tempC == 85) {
+                if (owTemp_feed >= 80 && owTemp_feed <= 90) _valueOK = true;
+            }
+            else _valueOK = true;
+
+            if (_valueOK) {
+                owTemp_out = tempC;
+                snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: sensor 'OUT' = %1.1f", owTemp_out);
+                sendLog(logBuf, LOGLEVEL_INFO);
+            }
         }
     }
     else {
@@ -222,11 +254,12 @@ void oneWireSensors_loadAssignments() {
     oneWireSensors_loadAssignments(false);
 }
 void oneWireSensors_loadAssignments(bool force) {
-    snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: assigning sensors...");
+    snprintf(logBuf, LOG_BUFFER_SIZE, "DS18B20: load sensor assignments...");
     sendLog(logBuf, LOGLEVEL_INFO);
 
     if(force) {
-        snprintf(logBuf, LOG_BUFFER_SIZE, "    forced.");
+        snprintf(logBuf, LOG_BUFFER_SIZE, "         FORCED");
+        sendLog(logBuf, LOGLEVEL_INFO);
         for (uint8_t i = 0; i < ONEWIRE_SENSORS_COUNT; i++) {
             oneWireSensor_assignedDevToIndex[i] = 255;
         }

+ 37 - 28
src/webserver.ino

@@ -515,9 +515,14 @@ void httpServerInit()
       else json["mqttreconn"] = mqtt_reconnects - 1;
 
       #ifdef FIRMWARE_VARIANT_HEATCONTROL
-        json["tempFeed"] = owTemp_feed;
-        json["tempReturn"] = owTemp_return;
-        json["tempOut"] = owTemp_out;
+        if (owTemp_feed > -50.0) json["tempFeed"] = round1(owTemp_feed);
+        else json["tempFeed"] = "-.-";
+
+        if (owTemp_return > -50.0) json["tempReturn"] = round1(owTemp_return);
+        else json["tempReturn"] = "-.-";
+
+        if (owTemp_out > -50.0) json["tempOut"] = round1(owTemp_out);
+        else json["tempOut"] = "-.-";
 
         if (heatcontrol_in_heat_request) json["heatReq"] = 1;
         else json["heatReq"] = 0;
@@ -546,6 +551,7 @@ void httpServerInit()
         if (heatcontrol_in_sw_disableControl_pump) json["cDisPump"] = 1;
         else json["cDisPump"] = 0;
         
+        json["useHeatC"] = confHeatc.useHeatCurve;
         json["currHeatC"] = heatcontrol_currentHeatCurveValue;
         json["currHeatCOff"] = heatcontrol_currentHeatCurveValue + confHeatc.hystereseOff;
         json["currHeatCOn"] = heatcontrol_currentHeatCurveValue - confHeatc.hystereseOn ;
@@ -566,37 +572,39 @@ void httpServerInit()
       #endif // FIRMWARE_VARIANT_HEATCONTROL
       
       #ifdef FIRMWARE_VARIANT_THERMOSTAT
-      json["setTemp"] = thermostat_setTemp;
-      json["currSetTemp"] = thermostat_currSetTemp;
-      json["actSetTemp"] = thermostat_currActualSetTemp;
-
-      uint8_t _heatingState;
-      if(thermostat_turnHeatingOn) _heatingState = 1;
-      else if(thermostat_heatingLockTime > 0) _heatingState = 2;
-      else _heatingState = 0;
-      
-      json["heating"] = _heatingState;
-      json["heatingLockTime"] = thermostat_heatingLockTime;
-      json["heatingPause"] = thermostat_heatingPause;
-      json["mode"] = thermostat_heatingMode;
-      json["modeName"] = thermostat_currentModeName;
-      json["pset"] = thermostat_preset;
-      json["psetName"] = thermostat_currentPresetName;
-      json["psetName0"] = confTherm.psetName0;
-      json["psetName1"] = confTherm.psetName1;
-      json["psetName2"] = confTherm.psetName2;
-      json["tempLow"] = thermostat_setTempLow;
-      json["tempLow2"] = thermostat_setTempLow2;
+        json["setTemp"] = thermostat_setTemp;
+        json["currSetTemp"] = thermostat_currSetTemp;
+        json["actSetTemp"] = thermostat_currActualSetTemp;
+
+        uint8_t _heatingState;
+        if(thermostat_turnHeatingOn) _heatingState = 1;
+        else if(thermostat_heatingLockTime > 0) _heatingState = 2;
+        else _heatingState = 0;
+
+        json["heating"] = _heatingState;
+        json["heatingLockTime"] = thermostat_heatingLockTime;
+        json["heatingPause"] = thermostat_heatingPause;
+        json["mode"] = thermostat_heatingMode;
+        json["modeName"] = thermostat_currentModeName;
+        json["pset"] = thermostat_preset;
+        json["psetName"] = thermostat_currentPresetName;
+        json["psetName0"] = confTherm.psetName0;
+        json["psetName1"] = confTherm.psetName1;
+        json["psetName2"] = confTherm.psetName2;
+        json["tempLow"] = thermostat_setTempLow;
+        json["tempLow2"] = thermostat_setTempLow2;
       #endif // FIRMWARE_VARIANT_THERMOSTAT
 
       #ifdef ENABLE_OUTSIDE_TEMP_MQTT
-      json["outTemp"] = round1(outTemp);
-      json["outHum"] = outHum;
+        json["outTemp"] = round1(outTemp);
+        json["outHum"] = outHum;
       #endif
 
       #ifdef ENABLE_SENSOR_DHT22
-      json["temp"] = round1(sensor_DHT_currTemp);
-      json["hum"] = int(sensor_DHT_currHum);
+        if (confSens.DHT_enable) {
+          json["temp"] = round1(sensor_DHT_currTemp);
+          json["hum"] = int(sensor_DHT_currHum);
+        }
       #endif
 
       char jsonchar[750];
@@ -732,6 +740,7 @@ void httpServerInit()
       #ifdef ENABLE_SENSOR_DHT22
         json["DHT_tempCorr"] = confSens.DHT_tempCorrVal;
         json["DHT_humCorr"] = confSens.DHT_humCorrVal;
+        json["DHT_enable"] = confSens.DHT_enable;
       #endif
 
       char jsonchar[1000];