while True:
temperature = dps310.temperature
mqtt_client.publish("foo", temperature)
try:
mqtt_client.loop()
except (MMQTTException) as e:
print("MQTTException: \n", e)
time.sleep(300)
continue
The documentation of the MMQTTException does not give any advice as to what to do if the exception is raised. Usually, the safest thing would be to reconnect() on the exception, notably because as indicated on https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/175#issuecomment-1902251442 the message data could be partially read and lost when the exception is raised which would result in garbage on the next read.
There are two choices:
easy: augment the MMQTTException docstring
more difficult: to allow for the graceful handling of the read timeout, the buffer should be kept around so that message reassembly can be performed
The common use case of the library is as follows (adapted from https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/163#issue-1689131569):
The documentation of the
MMQTTException
does not give any advice as to what to do if the exception is raised. Usually, the safest thing would be toreconnect()
on the exception, notably because as indicated on https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/issues/175#issuecomment-1902251442 the message data could be partially read and lost when the exception is raised which would result in garbage on the next read.There are two choices:
MMQTTException
docstring