TinkerWorks / HomeSensorHub

GNU General Public License v3.0
3 stars 2 forks source link

Reconnect mqtt on values changed #63

Open BabyCakes13 opened 1 year ago

BabyCakes13 commented 1 year ago

When the broker url and port are updated from the web app, the mqtt connection should stop and reconnect to the new values.

BabyCakes13 commented 1 year ago

Finished implementing the reconnection on values updated from the web interface. The only problem which I still have is that the callback function for reconnection is called for each entry:

Image

Resulting in reconnecting four times, in this case:

Image

I have to update the logic to only reconnect ONCE after its values are all updated.

This will be a bit tricky as each value is updated via a callback. There is no knowledge on when the "last" time this function is called, such that the reconnection has a green flag to go.

BabyCakes13 commented 1 year ago

Done. I implemented an object timer (for each section) which is reset every time a section update happens in the configuration. When the timer is not reset any more, that means that the sequence of entry updates for that section has finished and the callback function can be safely called:

Image

With this implementation, there is no need to check which entry is updated for which section. When there are a sequence of multiple entry updates for a section, the timer simply resets, blocking the call of the callback function:

Image

BabyCakes13 commented 1 year ago

Done in 93f22c2.