Skip to content
Advertisement

MQTT Python-Client disconnect ungracefully

I wrote basic MQTT python-client. But it disconnect ungracefully without giving any error. When i look event log file i found it’s connected and same time is disconnected ungracefully.

JavaScript

Here i attached a snap of event log also.

event log

Advertisement

Answer

@MikeScotty’s answer is not right. What’s missing is starting the MQTT network loop. The loop needs to be started to handle sending keep alive packets, doing multi leg handshakes for QoS 1/2 messages and to handle incoming subscriptions.

If you just want to stay connected or 10 seconds then something like this will work

JavaScript

If you want to stay connected forever (or until killed) then you have 2 options

JavaScript

This will start the network loop in the foreground (and as such block until killed).

Or

JavaScript

Or

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement