Closed Mollayo closed 2 years ago
I agree with this patch too -- it was causing a malformed packet when subscribing immediately after a connection; which is a pretty common thing to do.
Though a more compact way to do this might just be:
packet_id_counter = packet_id_counter == 0xffff ? 1 : packet_id_counter + 1;
Also, in publish, in the qos if block:
packnum = packnum == 0xffff ? 1 : packnum + 1;
@brentru : this is a pull request to address this issue: https://github.com/adafruit/Adafruit_MQTT_Library/issues/203
Packets whose index is 0 are considered as malformed packets by the MQTT broker. If such thing happens, the client is disconnected by the broker. The value of the packet_id_counter variable is now calculated in a way that it is always different from 0 to avoid unwanted disconnections.