I'm currently using the mosquittopp library in C++ to handle the connection with different devices (one at a time). When we decide to disconnect from device #1 (by unplugging it from the computer from example) ; I receive correctly the on_disconnect signal. After that, I do a lib_cleanup() and lib_init() to reinitialize the broker : if I don't do that, plugging in the device will immediately reconnect it (but I want to be able to let go of a connection manually).
However, even with that, after plugging in the device, I still receive the on_connect signal without having to input ip address and port.
Is there any way to safely and cleanly completely cleanup the connection from MQTT broker ? I'm expecting the issue to be because loop_forever() continues to run somehow, but even if I call stop() I still have the issues...
Here is the order of the calls and signals I have :
connectBrooker()
run() -> calls loop_forever()
on_connect()
// *operations here with messages and subscriptions*
// **unplugging the device** -> on_disconnect()
lib_cleanup()
lib_init()
// **plugging the device** -> after some small amount of time, on_connect() then run() -> calls loop_forever()