peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
549 stars 116 forks source link

Interest in 'unsubscribe' addition #90

Closed bobveringa closed 1 year ago

bobveringa commented 1 year ago

Is there any interest for adding an unsubscribe feature? For the system I am working on, it is sometimes required to subscribe to events for only a short duration. There are ways around this of course, but I'd rather not get the messages at all. It seems like this would only be a small addition to the code, that wouldn't take too much resource for people who are not using it.

peterhinch commented 1 year ago

This was a deliberate omission to save code size, on the grounds that few microcontroller apps would need it. I'll review this to assess how much it would add and report back.

bobveringa commented 1 year ago

If you don't want to spend the time investigating this, I could make an implementation which you can review?

rroemhild commented 1 year ago

@kevinkk525 has implemented unsubscribe in his fork. https://github.com/kevinkk525/micropython-mqtt/blob/6e25ac7568e55245a9d51f728203c1fb11e765b4/mqtt_as.py#L378

peterhinch commented 1 year ago

Thanks for that - I was about to start investigating this and this has saved me a lot of time.

Knowing the quality of @kevinkk525's work it will have been thoroughly tested and the implementation looks reasonably minimal (there is further code here and here).

I'll implement his solution, test, and assess the effect on code size.

peterhinch commented 1 year ago

I've pushed an update. Code size increase is 416 bytes or ~1.6%. See the note in the docs re unsubscribing from a nonexistent topic.