8000 MMQTTException vs partial reads on read timeout · Issue #201 · adafruit/Adafruit_CircuitPython_MiniMQTT · GitHub
[go: up one dir, main page]

Skip to content
MMQTTException vs partial reads on read timeout #201
Closed
@vladak

Description

@vladak

The common use case of the library is as follows (adapted from #163 (comment)):

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 #175 (comment) 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 to say a reconnect() is needed upon catching it
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0