MQTT interface reset on device restart

First time implementing/testing a driver code using the mqtt interface...

Whats the mechanism by which my driver's mqtt connection is re-esatblished after the hub reboots?

I put the connect call within installed() and check mqttClientStatus for disconnections, but I think the last time the hub rebooted, it did not seem to re-connect autoamtically.

The installed() method is only called once, when the device is first added to the hub. For things you want to happen on hub reboot, a common approach in a driver is to use capability "Initialize", along with its initialize() method that will be called on every hub reboot. This makes it useful for re-establishing connections like MQTT. (Note that this method does not do anything on its own in apps or in drivers without this capability.)

The updated() method is called every time you hit "Done" in the app and can also be a good place to check this kind of thing -- probably better thaninstalled() for initial setup, assuming you need any user-supplied data.

3 Likes