Browse Source

BUGFIXES:
- wrong value in MQTT out "currSetTemp"
- MQTT retained save did not work correctly

FloKra 3 years ago
parent
commit
d26c6655a1
1 changed files with 13 additions and 43 deletions
  1. 13 43
      src/mqtt_out.ino

+ 13 - 43
src/mqtt_out.ino

@@ -10,58 +10,28 @@ void publishCurrentThermostatValues(bool force = false)
   // most values are only published if changed
   // call publishCurrentThermostatValues(true); to force publishing an update
   char tmp_topic_out[50];
-
-  char ch_setTemp[6];
-  char ch_currSetTemp[6];
-  dtostrf(setTemp, 1, 1, ch_setTemp);
-  dtostrf(currSetTemp, 1, 1, ch_currSetTemp);
-
+  char ch_valuebuf[7];
+  
   updateCurrentHeatingModeName();
   updateCurrentPresetName();
 
-  // if (serialdebug)
-  // {
-  //   Serial.print(F("thermostat: {"));
-  //   Serial.print(F("'heatingMode':"));
-  //   Serial.print(heatingMode);
-  //   Serial.print(F(",'preset':"));
-  //   Serial.print(preset);
-  //   Serial.print(F(",'setTemp':"));
-  //   Serial.print(ch_setTemp);
-  //   Serial.print(F(",'currSetTemp':"));
-  //   Serial.print(ch_currSetTemp);
-  //   Serial.println("}");
-  // }
-
   char logBuf[101];
   sprintf_P(logBuf, "%s: %s=%u, %s=%u, %s=%2.1f, %s=%2.1f", PGMStr_thermostat, PGMStr_heatingMode, heatingMode, PGMStr_preset, preset, PGMStr_setTemp, setTemp, PGMStr_currentSetTemp, currSetTemp);
   sendLog(logBuf, LOGLEVEL_INFO);
 
-  //   Serial.print(F("thermostat: {"));
-  //   Serial.print(F("'heatingMode':"));
-  //   Serial.print(heatingMode);
-  //   Serial.print(F(",'preset':"));
-  //   Serial.print(preset);
-  //   Serial.print(F(",'setTemp':"));
-  //   Serial.print(ch_setTemp);
-  //   Serial.print(F(",'currSetTemp':"));
-  //   Serial.print(ch_currSetTemp);
-  //   Serial.println("}");
-  // }
-
   if (force || !confBas.saveToMqttRetained || setTemp != setTemp_lastPublished)
   {
     sprintf(tmp_topic_out, "%s/%s", confMqtt.mqtt_topic_out, "setTemp");
-    mqttclient.publish(tmp_topic_out, ch_setTemp, confMqtt.mqtt_outRetain);
+    sprintf(ch_valuebuf, "%2.1f", setTemp);
+    mqttclient.publish(tmp_topic_out, ch_valuebuf, confMqtt.mqtt_outRetain);
 
     if (confBas.saveToMqttRetained && setTemp != setTemp_lastPublished)
     {
-      //Serial.print("MQTT retained save setTemp: ");
-      //Serial.println(ch_setTemp);
+      // MQTT retained save setTemp
+      mqttclient.publish(mqtt_topic_in_setTemp, ch_valuebuf, true);
       char buf1[30];
       sprintf_P(buf1, "%s %s %2.1f", PGMStr_mqttRetainedSave, PGMStr_setTemp, setTemp);
       sendLog(buf1);
-      mqttclient.publish(mqtt_topic_in_setTemp, ch_setTemp, true);
     }
 
     setTemp_lastPublished = setTemp;
@@ -71,7 +41,8 @@ void publishCurrentThermostatValues(bool force = false)
   if (force || currSetTemp != currSetTemp_lastPublished || !confMqtt.mqtt_outRetain)
   {
     sprintf(tmp_topic_out, "%s/%s", confMqtt.mqtt_topic_out, "currSetTemp");
-    mqttclient.publish(tmp_topic_out, ch_currSetTemp, confMqtt.mqtt_outRetain);
+    sprintf(ch_valuebuf, "%2.1f", currSetTemp);
+    mqttclient.publish(tmp_topic_out, ch_valuebuf, confMqtt.mqtt_outRetain); 
 
     currSetTemp_lastPublished = currSetTemp;
     yield();
@@ -89,12 +60,12 @@ void publishCurrentThermostatValues(bool force = false)
 
     if (confBas.saveToMqttRetained && heatingMode != heatingMode_lastPublished)
     {
-      //Serial.print("MQTT retained save setMode: ");
-      //Serial.println(ch_heatingMode);
+      // MQTT retained save setMode
+      mqttclient.publish(mqtt_topic_in_setMode, ch_heatingMode, true);
       char buf1[30];
       sprintf_P(buf1, "%s %s %u", PGMStr_mqttRetainedSave, PGMStr_heatingMode, heatingMode);
       sendLog(buf1);
-      mqttclient.publish(mqtt_topic_in_setMode, ch_heatingMode, true);
+      
     }
 
     heatingMode_lastPublished = heatingMode;
@@ -119,12 +90,11 @@ void publishCurrentThermostatValues(bool force = false)
 
     if (confBas.saveToMqttRetained && preset != preset_lastPublished)
     {
-      //Serial.print("MQTT retained save setPreset: ");
-      //Serial.println(ch_preset);
+      // MQTT retained save setPreset
+      mqttclient.publish(mqtt_topic_in_setPreset, ch_preset, true);
       char buf1[30];
       sprintf_P(buf1, "%s %s %u", PGMStr_mqttRetainedSave, PGMStr_preset, preset);
       sendLog(buf1);
-      mqttclient.publish(mqtt_topic_in_setPreset, ch_preset, true);
     }
 
     preset_lastPublished = preset;