Closed rgorosito closed 3 years ago
@rgorosito Hi, thanks for submitting this PR. I agree completely with #2, thank you for adding it, it'll help the publish
function be more selective with what its reading out.
In 1),
Ping call processPacketsUntil which detect if call new message (appears in debug console), but can't be read in callback or readSubscription.
I'm confused here.
The way the library currently works, ping
is called which calls processPacketsUntil
. processPacketsUntil
waits for the broker to respond with a PINGRESP control packet. It should not obtain any other messages other than a PINGRESP. When would this not be the case?
The way the library currently works,
ping
is called which callsprocessPacketsUntil
.processPacketsUntil
waits for the broker to respond with a PINGRESP control packet. It should not obtain any other messages other than a PINGRESP. When would this not be the case?
the problem occurs when a new message reaches the subscriber between the ping that was sent and its response received. If you see the log 1:
out: PINGREQ [C0]
in: PUBLISH RECEPTION (sent from the mqtt server) [32]
out: PUBLISH ACK [32]
in: PINGRESP [D0]
When I'm working with the library, I detect that some event was lost. After enabled debug, I've detected 2 situations:
Ping call processPacketsUntil which detect if call new message (appears in debug console), but can't be read in callback or readSubscription. My fix add a boolean attribute "new_message" (default false) in Adafruit_MQTT_Publish class. It is set to true inside processPacketsUntil. Later, in readSubscription, search if there are pending message. If so, return that message. Callback don't need to be modified because it call readSubscription.
Sometimes my program fail to publish a message and loss subscription arrived (detected in debug console). The fix was more easy and clean: replase readFullPacket with processPacketsUntil. This permit that a message arrive when waiting for response on QoS>0 and because processPacketsUntil has the expected packet type, the check in the type in buffer is not needed anymore.
Logs
message are parsed, but never read
On publish waiting por ACK, ignore incomming messages and return an error because ACK come later.