Paho MQTT Python client: get all messages and disconnect [message #1861894] |
Fri, 10 November 2023 22:55 |
Mi Van![Friend of Eclipse Friend](https://www.eclipse.org/donate/web-api/friends_decorator.php?email=m%40sfio.win) Messages: 2 Registered: February 2023 |
Junior Member |
|
|
Using the Paho client I want to get all messages in a given topic and disconnect from the broker.
I can easily do this using simple() as shown here, yet only if I specify the message count using msg_count. This would be fine if the message count were predictable or if there was a means to count the messages in a given topic.
import paho.mqtt.subscribe as mqtt_subscribe
messages = mqtt_subscribe.simple('proxies/#', msg_count=4, hostname='mqtt.somewhere.io')
for m in messages:
print(m.payload.decode())
I'm also able to get all the messages in my topic using the example shown in Getting Started. However, this uses a loop_forever() and I simply want to get all messages and disconnect. I've tried other loop*() functions, yet none are offering the results I'm seeking.
The Callback Example also returns all messages yet it isn't clear to me how to disconnect from this.
And lastly, I can also use the mosquitto_sub client with a timeout to get all messages: mosquitto_sub -h mqtt.somewhere.io -t "proxies/#" -W 1 but I'd prefer to be consistent with the paho client and better understand it.
[Updated on: Fri, 10 November 2023 22:56] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.01849 seconds