growatt2mqtt icon indicating copy to clipboard operation
growatt2mqtt copied to clipboard

MQTT "error" topic is not cleared after succesful transmission

Open matthias-bs opened this issue 1 year ago • 2 comments

Hi Csongor,

if there was a Modbus communication error, e.g. error = Response timed out and communication is resumed normally, the MQTT topic "error" is not updated.

I think in ReadHoldingRegisters(), the "error" topic should also be updated if the condition (result == growattInterface.Success) is true (e.g. error = "none").

Besides, the message string should be put in double quotes, i.e. error = "Response timed out".

Regards Matthias

matthias-bs avatar Mar 11 '23 14:03 matthias-bs

Hi Matthias,

I was not planning to update the error topic with anything, after all once communication is up and running, you will start receiving messages in the data topic. Therefore the error topic keeps the data of the last reason the communication failed.

I am not sure what do you mean with double quotes, the message text is already in double quotes in the code.

Csongor

nygma2004 avatar Mar 13 '23 22:03 nygma2004

Hi Csongor,

You could have sporadic Modbus transmission errors, even after the communication was set up correctly.

The current output is error = Response timed out, but it should be error = "Response timed out", because the value is a string. (please compare to the other MQTT topics with strings) Most MQTT clients/JSON parsers seem to accept the former, but it could lead to problems with others.

To achieve this in the code, you can write

message = "\"" + message + "\""; 
mqtt.publish(topic, message.c_str());

Best regards, Matthias

matthias-bs avatar Mar 14 '23 06:03 matthias-bs