Closed lu-maca closed 1 week ago
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718099 The MQTT protocol allows discarding messages with a QoS equal to 0。 You can switch to a different MQTT broker or specify the QoS。
The publisher client is not running. You never called loop/loop_start or loop_forever. It also seems you never wait for publisher to finish publishing (no disconnect, no even a arbitrary sleep). Call to publish isn't synchronous and don't wait to publish packet to be received by broken (which isn't possible in QoS=0).
Publish() will only submit packet to the TCP socket, and OS might no send them on network immediately. I'm not 100% sure, but I think that OS is allowed to discard not yet send data on socket close (which happen if you terminate the program). That why adding some sleep (a sleep at the end of publisher.py is enough) "solve" your problem. A fix should be to start the client (loop_forever) and disconnect + wait for disconnection before exiting.
A better solution is paho.mqtt.publish (https://github.com/eclipse/paho.mqtt.python#id3) which take care of all needs to send message.
Closing due to inactivity (and it looks like an answer has been provided).
Hi,
I'm trying to run a simple publisher-subscriber example but a really weird behaviour happens:
When I run
publisher.py
, the weird stuff happens:It seems that the publisher is not sending messages correctly. When a
time.sleep(0.05)
is added between the publish operations, it works fine:Why does this happens? Am I doing something wrong?
Thanks! Luca