gysmo38 / mitsubishi2MQTT

Mitsubishi to MQTT with ESP8266 module
GNU Lesser General Public License v2.1
390 stars 139 forks source link

Help to explain some MQTT commands #75

Closed picotouch closed 4 years ago

picotouch commented 4 years ago

HI, in Readme the last chapter contains a list of topics. Please explain some of them (bold expressions).

And finally, if on the web portal in Setup / Others, I set HA Autodisovery to OFF, after save & reboot, the state is ON again? I don't use HA, but is this a bug?

Thanks!!

juampe commented 4 years ago

AFAIK topic/remote_temp/set is for external thermometer, it maps the room_temp parameter from the original library, in theory you can set it from another sensor. It seems not work in my MSZ-HR.

topic/debug/set I can see the _debugMode in the code but, but it does not publish the "Debug mode enabled/disables/message" as i set to on or off to the topic, "it seems a bug".

topic/custom/send is for send raw packets, see https://github.com/SwiCago/HeatPump/blob/master/src/HeatPump.h , it needs knoledge of the raw protocol.

juampe commented 4 years ago

About the topic/debug/set I have to made little change to see why debug does not work. I am not familiarized with the F function (RTFM for me), but if I remove it, the code works as expected, and mqtt debug is operational. I compile with PIO ESP8366 2.5.1

diff --git a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
index 5619a66..a308706 100644
--- a/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
+++ b/src/mitsubishi2mqtt/mitsubishi2mqtt.ino
@@ -1433,10 +1433,10 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) {
   else if (strcmp(topic, ha_debug_set_topic.c_str()) == 0) { //if the incoming message is on the heatpump_debug_set_topic topic...
     if (strcmp(message, "on") == 0) {
       _debugMode = true;
-      mqtt_client.publish(ha_debug_topic.c_str(), (char*)(F("Debug mode enabled")));
+      mqtt_client.publish(ha_debug_topic.c_str(), (char*)"Debug mode enabled");
     } else if (strcmp(message, "off") == 0) {
       _debugMode = false;
-      mqtt_client.publish(ha_debug_topic.c_str(), (char*)(F("Debug mode disabled")));
+      mqtt_client.publish(ha_debug_topic.c_str(), (char*)"Debug mode disabled");
     }
   }
   else if(strcmp(topic, ha_custom_packet.c_str()) == 0) { //send custom packet for advance user
juampe commented 4 years ago

Seems that we found a 32 bit alignment problem, related to the use of the F() macro in this code section https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html

The two examples above will store these strings in flash. To retrieve and manipulate flash strings they must be read from flash in 4byte words. In the Arduino IDE for esp8266 there are several functions that can help retrieve strings from flash that have been stored using PROGMEM. Both of the examples above return const char *. However use of these pointers, without correct 32bit alignment you will cause a segmentation fault and the ESP8266 will crash. You must read from the flash 32 bit aligned.

Now I have 2 suspicions Suspicion 1 The knolleary MQTT library seems not to be ready for F() handle https://pubsubclient.knolleary.net

boolean publish(const char topic, const char payload); boolean publish(const char topic, const char payload, boolean retained); boolean publish(const char topic, const uint8_t payload, unsigned int plength); boolean publish(const char topic, const uint8_t payload, unsigned int plength, boolean retained); boolean publish_P(const char topic, const char payload, boolean retained); boolean publish_P(const char topic, const uint8_t payload, unsigned int plength, boolean retained);

Suspicion 2 The imroy MQTT library seems to handle F() correctly https://imroy.github.io/pubsubclient/classMQTT_1_1Publish.html

Publish (String topic, const __FlashStringHelper *payload) Constructor from a string stored in flash using the F() macro.

picotouch commented 4 years ago

@juampe, thanks for explaining and updating Readme.md!