xoseperez / espurna

Home automation firmware for ESP8266-based devices
http://tinkerman.cat
GNU General Public License v3.0
3k stars 638 forks source link

Is there an mqtt echo functionality? #2618

Open CrappyTan opened 1 month ago

CrappyTan commented 1 month ago

Device

No response

Version

No response

Question

After our last discussion around mqtt and LWT, I need to be 100% certain a devices is online.

My use-case, I am controlling a heater which is keeping a large number of Lithium batteries warm through winter. As such, it needs to be belt and braces to ensure I don't cook the batteries (and the heater has the capacity to do this)

Whist LWT is good to alert of subscribers vanishing, it does not, I believe, protect from the broker crashing. Certainly not in my testing. (There is a safety mechanism - SWITCH=OFF ON BROKER DISCONNECT which I already have set)

To work around this, I "poll" the relay. I send a message pattern to the relay relay/0/set and process the sequence coming back via the relay/0 topic. If I get the same patter, I know we're online.

This obviously causes chatter and the PSU / fans don't much appreciate it.

What would be very simple if there was an "echo" function. I sent a value to echo/set and it would reply on /echo with the same value.

/echo or /alive - same thing.

is something like this there? I cannot see anything in the code.

If not, I will implement it for myself - thoughts on a wider use / inclusion in the codebase?

mcspr commented 1 month ago

I do see <root>/action/set receiving heartbeat would schedule one immediately. Heartbeat usually contains status, unless disabled via settings / build flags.

Whist LWT is good to alert of subscribers vanishing, it does not, I believe, protect from the broker crashing. Certainly not in my testing. (There is a safety mechanism - SWITCH=OFF ON BROKER DISCONNECT which I already have set)

To work around this, I "poll" the relay. I send a message pattern to the relay relay/0/set and process the sequence coming back via the relay/0 topic. If I get the same patter, I know we're online.

Subscribers in this case are Espurna devices? Is the idea for the device to do something when there are no ping->pong / alive / echo payloads? If the idea is to keep relay ON and OFF otherwise, doesn't pulse timer already do that?

Courtesy reminder that MQTT is not request->response, but publisher->subscriber (...or, at least it is without MQTTv5 optional publish flag that does that... :)