Browse Source

Rohdaten Temperatur/Feuchte - Ausgabe via MQTT hinzugefügt, fehlende Konfigurationsparameter in saveConfig2() sowie loadConfig2() ergänzt, Bugfix Glättung Temperaturmessung,
div weitere bugfixes

FloKra 6 years ago
parent
commit
1336d3509d

+ 4 - 4
src/WiFiThermostat/Display.ino

@@ -82,8 +82,8 @@ void updateDisplay() {
   else {
     if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
       showTemp = true;
-      dtostrf(temperature, 5, 1, temp_chararr );
-      sprintf(hum_chararr, "%2i", humidity);
+      dtostrf(currTemp, 5, 1, temp_chararr );
+      sprintf(hum_chararr, "%2i", currHum);
       strcpy(tempLabel, "I");
     }
   }
@@ -100,8 +100,8 @@ void updateDisplay() {
     lcd.write(0xDF); // degree symbol
     lcd.print(" ");
 
-    if (humidity == 0) lcd.print("--");
-    else if (humidity < 10) {
+    if (currHum == 0) lcd.print("--");
+    else if (currHum < 10) {
       lcd.print(" ");
       lcd.print(hum_chararr);
     }

+ 6 - 4
src/WiFiThermostat/WiFiThermostat.ino

@@ -99,8 +99,8 @@ int domoticzIdx_TempHumSensor = 0;
 int domoticzIdx_PIR = 0;
 char outTemp_topic_in[51];
 char outHum_topic_in[51];
-bool autoSaveSetTemp = true;
-bool autoSaveHeatingMode = true;
+boolean autoSaveSetTemp = true;
+boolean autoSaveHeatingMode = true;
 int heatingMinOffTime = 10;       // minimal time the heating keeps turned off in s
 float setTempMin = 14.0;        // minimal temperature that can be set
 float setTempMax = 29.0;        // maximal temperature that can be set
@@ -128,8 +128,10 @@ int debounceTime = BUTTON_DEBOUNCE_TIME;
 int buttonHoldTime = BUTTON_HOLD_TIME;
 
 // global variables
-float temperature; // last reading from DHT sensor
-int humidity; // last reading from DHT sensor
+float currTemp; // last reading from DHT sensor
+float currTemp_raw; // last reading from DHT sensor
+int currHum; // last reading from DHT sensor
+int currHum_raw; // last reading from DHT sensor
 bool turnHeatingOn = false; // true if heating is active (relais switched on)
 unsigned long heatingLastOnMillis; // last time heating was switched on
 unsigned long heatingLastOffMillis; // last time heating was switched off

+ 48 - 2
src/WiFiThermostat/config.ino

@@ -411,6 +411,8 @@ void printConfig2() {
   Serial.println(setTempMin);
   Serial.print("tempMax: ");
   Serial.println(setTempMax);
+  Serial.print("tempLow: ");
+  Serial.print(setTempLow);
   Serial.print("hyst: ");
   Serial.println(hysteresis);
   Serial.print("tempCorr: ");
@@ -546,6 +548,25 @@ bool loadConfig2() {
       domoticzIdx_ThermostatMode = atoi(json["domIdxMode"] | "");
       domoticzIdx_TempHumSensor = atoi(json["domIdxTempHum"] | "");
       domoticzIdx_PIR = atoi(json["domIdxPIR"] | "");
+      strlcpy(outTemp_topic_in, json["outTempTop"] | "", 51);
+      strlcpy(outHum_topic_in, json["outHumTop"] | "", 51);
+
+      if (atoi(json["autoSaveTemp"] | "") == 1) autoSaveSetTemp = true;
+      else autoSaveSetTemp = false;
+
+      if (atoi(json["autoSaveMode"] | "") == 1) autoSaveHeatingMode = true;
+      else autoSaveHeatingMode = false;
+
+      heatingMinOffTime = atoi(json["minOffTime"] | "");
+      setTempMin = atof(json["tempMin"] | "");
+      setTempMax = atof(json["tempMax"] | "");
+      setTempLow = atof(json["tempLow"] | "");
+      hysteresis = atof(json["hyst"] | "");
+      tempCorrVal = atof(json["tempCorr"] | "");
+      humCorrVal = atoi(json["humCorr"] | "");
+      measureInterval = atoi(json["measInt"] | "");
+      displayInterval = atoi(json["dispInt"] | "");
+      displayTimeout = atoi(json["dispTout"] | "");
 
       Serial.println("Loaded config values:");
       printConfig2();
@@ -606,10 +627,16 @@ bool saveConfig() { // safeConfig
   json["mqttPass"] = mqtt_pass;
   json["inTop"] = mqtt_topic_in;
   json["outTop"] = mqtt_topic_out;
-  json["outRet"] = mqtt_outRetain;
+
+  if(mqtt_outRetain) json["outRet"] = 1;
+  else json["outRet"] = 0;
+  
   json["willTop"] = mqtt_willTopic;
   json["willQos"] = mqtt_willQos;
-  json["willRet"] = mqtt_willRetain;
+  
+  if(mqtt_willRetain) json["willRet"] = 1;
+  else json["willRet"] = 0;
+  
   json["willMsg"] = mqtt_willMsg;
   json["domOutTop"] = domoticz_out_topic;
 
@@ -635,6 +662,25 @@ bool saveConfig2() { // safeConfig2
   json["domIdxMode"] = domoticzIdx_ThermostatMode;
   json["domIdxTempHum"] = domoticzIdx_TempHumSensor;
   json["domIdxPIR"] = domoticzIdx_PIR;
+  json["outTempTop"] = outTemp_topic_in;
+  json["outHumTop"] = outHum_topic_in;
+
+  if(autoSaveSetTemp) json["autoSaveTemp"] = 1;
+  else json["autoSaveTemp"] = 0;
+
+  if(autoSaveHeatingMode) json["autoSaveMode"] = 1;
+  else json["autoSaveMode"] = 0;
+  
+  json["minOffTime"] = heatingMinOffTime;
+  json["tempMin"] = setTempMin;
+  json["tempMax"] = setTempMax;
+  json["tempLow"] = setTempLow;
+  json["hyst"] = hysteresis;
+  json["tempCorr"] = tempCorrVal;
+  json["humCorr"] = humCorrVal;
+  json["measInt"] = measureInterval;
+  json["dispInt"] = displayInterval;
+  json["dispTout"] = displayTimeout;
 
   yield();
 

+ 2 - 2
src/WiFiThermostat/domoticz.ino

@@ -179,8 +179,8 @@ void sendToDomoticz_TempHum() {
       //{"idx":idx,"nvalue":0,"svalue":"TEMP;HUM;0"}
       char buf[101];
       char buftemp[10];
-      dtostrf(temperature, 1, 1, buftemp );
-      sprintf(buf, "{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s;%d;0\"}", domoticzIdx_TempHumSensor, buftemp, humidity);
+      dtostrf(currTemp, 1, 1, buftemp );
+      sprintf(buf, "{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s;%d;0\"}", domoticzIdx_TempHumSensor, buftemp, currHum);
       mqttclient.publish(DOMOTICZ_IN_TOPIC, buf);
     }
   }

+ 2 - 2
src/WiFiThermostat/httpServer.ino

@@ -425,8 +425,8 @@ void httpServerInit() {
     json["devname"] = deviceName;
     json["ssid"] = WiFi.SSID();
     json["setTemp"] = setTemp;
-    json["temp"] = temperature;
-    json["hum"] = int(humidity);
+    json["temp"] = currTemp;
+    json["hum"] = int(currHum);
     json["mode"] = heatingMode;
     json["heating"] = turnHeatingOn;
 

+ 19 - 4
src/WiFiThermostat/mqtt.ino

@@ -252,8 +252,8 @@ void publishCurrentSensorValues() {
 
     char temp_chararr[6];
     char hum_chararr[4];
-    dtostrf(temperature, 1, 1, temp_chararr );
-    sprintf(hum_chararr, "%2i", humidity);
+    dtostrf(currTemp, 1, 1, temp_chararr );
+    sprintf(hum_chararr, "%2i", currHum);
 
     Serial.print("temp: '");
     Serial.print(temp_chararr);
@@ -261,11 +261,26 @@ void publishCurrentSensorValues() {
     sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "temp");
     mqttclient.publish(tmp_topic_out, temp_chararr);
 
-    Serial.print("humidity: '");
-    Serial.print(humidity);
+    Serial.print("hum: '");
+    Serial.print(currHum);
     Serial.println("'");
     sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "hum");
     mqttclient.publish(tmp_topic_out, hum_chararr);
+
+    dtostrf(currTemp_raw, 1, 1, temp_chararr );
+    sprintf(hum_chararr, "%2i", currHum_raw);
+
+    Serial.print("temp_raw: '");
+    Serial.print(temp_chararr);
+    Serial.println("'");
+    sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "temp_raw");
+    mqttclient.publish(tmp_topic_out, temp_chararr);
+
+    Serial.print("hum_raw: '");
+    Serial.print(currHum_raw);
+    Serial.println("'");
+    sprintf(tmp_topic_out, "%s/%s", mqtt_topic_out, "hum_raw");
+    mqttclient.publish(tmp_topic_out, hum_chararr);
   }
 }
 

+ 14 - 9
src/WiFiThermostat/thermostat.ino

@@ -1,6 +1,6 @@
 void measureTempHum() {
-  float tmpHum = round(dht.readHumidity());
-  float tmpTemp = dht.readTemperature();  // Read temperature as Celsius (the default)
+  float tmpHum = round(dht.readHumidity()) + tempCorrVal;
+  float tmpTemp = dht.readTemperature() + humCorrVal;  // Read temperature as Celsius (the default)
 
   int tmpHumInt = tmpHum;
 
@@ -12,18 +12,21 @@ void measureTempHum() {
   else {
     if (tmpTemp < 50.0 && tmpTemp > -20.0) {
       // measurement is in range
-      if ( lastTempUpdate > 0 && tmpTemp <= ( temperature + 2.0 ) && tmpTemp >= ( temperature - 2.0 ) ) {
+      currTemp_raw = tmpTemp;
+      currHum_raw = tmpHumInt;
+      
+      if ( lastTempUpdate > 0 && tmpTemp <= ( currTemp + 2.0 ) && tmpTemp >= ( 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;
-        temperature = ((temperature * 9 + tmpTemp) / 10) + tempCorrVal; // filter
-        humidity = tmpHumInt + humCorrVal;
+        currTemp = (currTemp * 9 + tmpTemp) / 10; // filter
+        currHum = (currHum * 9 + tmpHumInt) / 10; // filter
         lastTempUpdate = millis();
       }
       else if ( lastTempUpdate == 0 || (millis() - lastTempUpdate) > 300000 ) {
         // this is the first measurement or the last one is older than 5m - then accept this measurement
-        temperature = tmpTemp + tempCorrVal;
-        humidity = tmpHumInt + humCorrVal;
+        currTemp = tmpTemp + tempCorrVal;
+        currHum = tmpHumInt + humCorrVal;
         lastTempUpdate = millis();
 
       }
@@ -35,6 +38,8 @@ void measureTempHum() {
       //      Serial.print(lastTempUpdateDelta / 1000);
       //      Serial.println("s ago");
       //#endif
+
+      
     }
   }
 }
@@ -81,7 +86,7 @@ void thermostat() {
 #endif
 
     // thermostat with hysteresis
-    if ( turnHeatingOn && temperature >= curr_setTemp ) {
+    if ( turnHeatingOn && currTemp >= curr_setTemp ) {
       turnHeatingOn = false;
       heatingLastOffMillis = millis();
       digitalWrite(PIN_RELAIS, !RELAISONSTATE);
@@ -95,7 +100,7 @@ void thermostat() {
       //mqttclient.publish(tmp_topic_out, "off");
       publishCurrentThermostatValues();
     }
-    else if ( !turnHeatingOn && heatingMode > 0 && ( temperature < (curr_setTemp - hysteresis) ) && ( heatingOffTime > heatingMinOffTime ) ) {
+    else if ( !turnHeatingOn && heatingMode > 0 && ( currTemp < (curr_setTemp - hysteresis) ) && ( heatingOffTime > heatingMinOffTime ) ) {
       turnHeatingOn = true;
       heatingLastOnMillis = millis();
       digitalWrite(PIN_RELAIS, RELAISONSTATE);