Open lgeuder opened 1 year ago
I would suggest using loop_start()
instead of the while loop that calls self.loop() - this creates a background thread that doesn't block your code and will reconnect for you in case of a connection failure. I would also suggest putting your call to subscribe() in your on_connect callback - that means it will be recreated on a reconnect.
Finally, in your publish()
function you should call super.publish()
to access the publish function of the base class.
I hope that helps.
Hi, I have created a class that should handle my mqtt publish dynamically (I used the class example:) )
I have added this publish function in hope that i can call mqttc.publish() from whereever I want. As this is not working at all I am beginning to think that I haven't understood way mqtt works... Is there a way I can open a connection (in a Thread - it should not block my script where I call publish()) and just pass channel and payload an this gets published to the localhost which I can connect?