[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[paho-dev] Offline buffering in Python3 Paho MQTT client
|
- From: Lars Noodén <lars.nooden@xxxxxxxxx>
- Date: Wed, 7 Oct 2020 15:27:36 +0300
- Autocrypt: addr=lars.nooden@xxxxxxxxx; keydata= mQINBFMwE5UBEADohhbeU/1lQZ1d9TN6ePhW/vw42MvasRrWJpf2t6D/y0xxbpMZTWRCgQ37 9UwAUATwfPKQ8ScZZaiTzQYZ+yAWkeOu/4BcOCr+k1KT1fW33lspRbMmmnf0OljbGazi01+F qXiC5pPvk3fj6nlSTI3GreV8bLxuTDltCnkkkxkgkd6W8MfEwCBGJySrk5ljnhIAi9PjClzs /qw/twOtHGy1EkH2huPgTOHmybgjOjz+3H19KHBnwSyZQ5me9ftWpUmaAMeImVW7nGNTqpUD NR01pELI8LwYzI6v8a95qflY0SKYu6bKg7sNlEvwFqm+ox6jBrm/w5dNhz71IJJDRa3Cpugf a64YZC021taHdTvs8fYqUOyYzh8g9ilkfD+fkJ6nR+2PUx9yeLBKCsJT0bkNdFGhmmD9aafD LMRhbFCHanEGERT89LRWpb26TTjdWn9Bv3n4TKc3gGX7YhFqACEOfB8zFIfb+cVASmpTU76z +hVTFbQcr8Vr67528ehiQFUvlptHgZlo24p8HhbKiKlLUEshL7KjDcXnUyiMoXNxkcZ99spY eWAMaapaipsGLTMfjEBxt5hxVti0ewTFc28sdbVY2jOesAIiNWhrxFEIhWW09o2PO9Z+3XRO Z/Hkrud0ofx2zVXwPmHhZ61yQkp+c9aso/rkMVojiVbsoy2jbQARAQABtCRMYXJzIE5vb2TD qW4gPGxhcnMubm9vZGVuQGdtYWlsLmNvbT6JAlUEEwEKAD8CGwMGCwkIBwMCBhUIAgkKCwQW AgMBAh4BAheAFiEEU75BlAiumCkMIiuL3vIKtmU86ucFAl554IsFCQ0rAHEACgkQ3vIKtmU8 6udhvhAA3Rj2ZybQvtOf4od6QU3/CaiHK82uHRcakdkC/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
- List-archive: <https://www.eclipse.org/mailman/private/paho-dev>
- List-help: <mailto:paho-dev-request@eclipse.org?subject=help>
- List-subscribe: <https://www.eclipse.org/mailman/listinfo/paho-dev>, <mailto:paho-dev-request@eclipse.org?subject=subscribe>
- List-unsubscribe: <https://www.eclipse.org/mailman/options/paho-dev>, <mailto:paho-dev-request@eclipse.org?subject=unsubscribe>
- User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0
Hello, paho-dev list members,
The Eclipse web site mentions this list as the place to discuss Paho
clients. Though I see in the archives little about python specifically.
If there is a more appropriate venue for this kind of usage question,
please point it out.
I am trying to have a Python3-based Paho MQTT client do offline
buffering during longer intervals when there is no network connectivity.
Can someone please point me to the right documentation and/or a code
snippet showing the right way to do that? Short intervals work but not
longer ones.
The examples I've found so far seem to have offline buffering disabled.
The documentation [1] suggests that enabling it might only be a matter
of setting clean_session to 'False', but that alone appears to be
insufficient for longer connectivity outages.
I have a test script [2] otherwise working. It sends data to the MQTT
broker just fine while there is network connectivity and resumes sending
once the connectivity is restored after a short period of disconnection.
However, the messages which would have been sent during a longer period
without connectivity seem to disappear completely. I would have
expected the client to have kept a queue which gets sent in bulk once
the connection is re-established.
What should I modify in the script below and/or what should I read in
the documentation?
Regards,
Lars
PS. Thank you in advance for not top-posting.
--
[1] https://pypi.org/project/paho-mqtt/#client
https://www.eclipse.org/paho/index.php?page=clients/python/docs/index.php#network-loop
[2]
#!/usr/bin/python3
import time
import paho.mqtt.client as mqtt
import ssl
def on_connect(client, userdata, flags, rc):
print("Connection returned result: "+connack_string(rc))
def on_disconnect(client, userdata, rc):
if rc != 0:
print("Unexpected disconnection.")
else:
print("MQTT disconnected")
mqtthost = "server.example.com"
mqttport = 8883
mqttclient = mqtt.Client(client_id="test1and2",
clean_session=False,
transport="tcp")
mqttclient.username_pw_set("foo", password="bar")
mqttclient.reconnect_delay_set(min_delay=1, max_delay=120)
mqttclient.tls_set(
ca_certs='/etc/mosquitto/certs/mqtt-server.crt',
certfile='/etc/mosquitto/certs/pub-client.crt',
keyfile ='/etc/mosquitto/certs/pub-client.key',
tls_version=ssl.PROTOCOL_TLSv1_2
)
mqttclient.on_connect = on_connect
mqttclient.on_disconnect = on_disconnect
mqttclient.connect(mqtthost, mqttport)
mqttclient.loop_start()
while True:
epoch = int(time.clock_gettime(0))
msg = str(epoch)+"\t9\t"+str(time.strftime("%H:%M"))
try:
mqttclient.publish("temperatures", payload=msg)
print("temperatures", msg)
except:
mqttclient.reconnect()
print("Reconnect")
time.sleep(5)