kopia lustrzana https://github.com/micropython/micropython-lib
umqtt.robust: Add universal with_retry method, and publish_() using it.
This method uses more memory though.mqtt
rodzic
4dc1f1c264
commit
d3d0b4f0b5
|
@ -26,6 +26,18 @@ class MQTTClient(simple.MQTTClient):
|
||||||
i += 1
|
i += 1
|
||||||
self.delay(i)
|
self.delay(i)
|
||||||
|
|
||||||
|
def with_retry(self, meth, *args, **kwargs):
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
return meth(*args, **kwargs)
|
||||||
|
except OSError as e:
|
||||||
|
print("%r" % e)
|
||||||
|
time.sleep(0.5)
|
||||||
|
self.reconnect()
|
||||||
|
|
||||||
|
def publish_(self, *args, **kwargs):
|
||||||
|
return self.with_retry(super().publish, *args, **kwargs)
|
||||||
|
|
||||||
def publish(self, topic, msg, retain=False, qos=0):
|
def publish(self, topic, msg, retain=False, qos=0):
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
|
|
Ładowanie…
Reference in New Issue