adafruit / Adafruit_MQTT_Library

Arduino library for MQTT support
MIT License
571 stars 292 forks source link

packets are dropped after connect if retain is set on server #164

Closed luckyhacky closed 3 years ago

luckyhacky commented 4 years ago

add barrier in connect() function for processing MQTT subscriptions packets which are sent with retain bit in subscriptions fixes "Dropped a packet" after connect with two or more subscriptions active

client view:

send connect < receive connect subscribe < suback subscribe < illegal packet < suback subscribe < illegal packet < suback

server view: < send connect

receive connect < subscribe suback send subscription update (retain value) < subscribe < suback send subscription update (retain value) < subscribe suback send subscription update (retain value)

So the server sends the last retain value, which is processed after new subscription but the client expects a SUBACK packet and not a publish one. This happens only on multiple subscriptions at connect.

Disadvantages:

brentru commented 3 years ago

merged existing PR https://github.com/adafruit/Adafruit_MQTT_Library/pull/170 which addresses this issue without the drawback of increasing connect() by 500ms for each subscription call.