deiger / Alarm

Code to connect and control alarms by PIMA.
GNU General Public License v3.0
16 stars 11 forks source link

Reconnect to MQTT broker on failures #13

Closed pavius closed 3 years ago

pavius commented 3 years ago

Today, if the MQTT broker restarts, the client connection drops or even if there's an exception (i.e. "GarbageInput") during arming/disarming over MQTT - no reconnection attempt is made and the application is effectively dead.

This addresses these issues by:

  1. Moving registration/LWT declaration to on_connect
  2. Implementing on_disconnect which calls connect
  3. Logging exceptions when handling MQTT messages rather than propagating them

In addition, adds some basic debug logs.

Tested by:

  1. Restarting MQTT broker
  2. Forcing pima_server off the network and then adding it back

Still observing long term effects of this, but happy for feedback in the interim.

deiger commented 3 years ago

Looks good, thank you.