lora-aprs / LoRa_APRS_iGate

This is a LoRa APRS iGate/Digi based on an ESP32
https://www.lora-aprs.info
MIT License
331 stars 106 forks source link

Implement MQTT "last will" and "birth message" #273

Closed tht closed 1 year ago

tht commented 1 year ago

First, thanks a lot for this lovely piece of software. I'm only missing an antenna before I'll be able to put an iGate on the roof.

For me there was one important part missing. Some kind of trivial monitoring if the iGate is still working. MQTT has this nice feature of a last will, where the broker/server itself publishes to a topic as soon as the connection to the client is lost. This is how it works.

  1. When connecting to MQTT we provide a last will topic and message. I use the message offline.
  2. After connecting to MQTT send the birth message to the last will topic. I use online.
  3. As long as the iGate is connected to MQTT the message will read online.
  4. When the iGate looses the MQTT connection (for whatever reason), the MQTT broker changes the message to the one provided as last will which is offline.

Please note. The last will and birth messages do have the retain flag set. So the message is retained on the broker and always available.

Please consider to merge this change. I hope I was able to follow your coding style. It works fine for me since a few days and I'm quite happy with it even if I don't like the nesting in src/TaskMQTT.cpp MQTTTask::connect.

Feel free to modify whatever you don't like or discard this PR if it is not what you are looking for in this project.

peterus commented 1 year ago

thanks @tht for your changes! i will definitely merge your changes! you can leave the merge request as it is now, i will fix the formating tomorrow for you 😉 I just have seen that there is also a problem with remote testing which i need to take a look on.

tht commented 1 year ago

That's fantastic :) and thanks for fixing the formatting.

peterus commented 1 year ago

@tht your MR is still in my head and on my list! Waiting to have time to look at it 😂

peterus commented 1 year ago

@tht thanks for the changes!