MQTT QOS are defined as:
0: The broker/client will deliver the message once, with no confirmation.
1: The broker/client will deliver the message at least once, with confirmation required.
2: The broker/client will deliver the message exactly once by using a four step handshake.
I'm running node-red on a raspberry pi (rpi) as the main contrtol unit and espeasy on remote esp2866 devices to control things like heaters. Communication between everything is done solely by MQTT.
I've encountered some recent situations where the esp2866 heater control gets out of sync with the known state on the RPI due to MQTT messages getting lost. ie.
- RPI sends a MQTT command to the ESPEasy controlled heater heater/gpio/13 to turn the switch off.
- espeasy heater turns off switch and then publishes the switch state on mqtt:heater/power/state.
- Unfortunately this message never reaches the mqtt broker, so the RPI (and all other subscribing clients) think that the heater is still on.
- Because the RPI thinks the heater is on, it continues to try to turn the heater off by publishing mqtt commands to heater/gpio/13, but because the switch is already off, espeasy doesn't publish any state change on the mqtt topic heater/power/state.
- Support a more robust QOS for MQTT. There is an async mqtt client that supports QOS 0, 1 & 2 that could work https://github.com/marvinroger/async-mqtt-client. It seems to support both persistent session and non-persistent sessions. Will likely increase the memory footprint.
- Return state of ESPEasy switch on receipt of every command. ie. when ESPEasy receives a command to turn a switch off, it will publish the current state of the switch even if it doesn't change the state of the switch. In the above example, while the first publish to mqtt:heater/power/state on step 2 may have failed, a subsequent command in step 4 would result in a publish of the current state. I believe another library https://github.com/arendst/Sonoff-Tasmota does this effectively where it publishes the current state response for all command control actions received.
Code: Select all
heater/power/control 1
where 'heater' is the espeasy device and 'power' is the swtich device.
Code: Select all
heater/gpio/13 1