mqtt – check python paho qtt connection created
If you want to publish a single message and then disconnect use single; this will “publish a single message to a broker, then disconnect cleanly”. i.e.:
single(topic, payload=None, qos=0, retain=False, hostname="localhost",
port=1883, client_id="", keepalive=60, will=None, auth=None, tls=None,
protocol=mqtt.MQTTv311, transport="tcp")
The repo includes an example for multiple (pretty much the same as single but sends more than one message).
If you want to do this yourself then take a look at how single is implemented and follow the same pattern (i.e. start a message loop and use the call backs; you can add your own logging in _on_connect if you want to see when the connection is up).
If you just want logs then use enable_logger(); this example demonstrates that.
Read more here: Source link
