Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Embedded-C dropping PUBACKs

Hi all,

I am using the Paho embedded-C code in an Arduino environment (i.e. single threaded, no RTOS) and am running into an issue with QoS-1 PUBACKs frequently not getting sent to the broker. I've looked at the source code and I think I see the problem, but I want to make sure I'm not missing anything.

My program's main loop calls MQTT::Client::yield() with a timeout of 200 mS.  yield() starts a timer for 200 mS and calls cycle() until either the timer expires or cycle() returns an error.

cycle() in turn reads a packet, deserializes it, and if it's a PUBLISH message, delivers it to my handler, and if it's QoS1 (or 2, although I'm not using QoS2), sends a PUBACK by calling sendPacket().  

sendPacket() then tries to write the data to the ipStack until EITHER all the data is sent OR the timer expires.

What appears to be happening is that a new PUBLISH message comes in late in my 200 mS yield time, and by the time sendPacket() is called, the timer has expired, so the PUBACK never gets sent.  This results in the broker resending the message even though my client got the initial message just fine.  This is happening annoyingly often for me.

Is that an expected scenario?  It doesn't affect the integrity of the published data, but it does increase network traffic and the burden of dealing with duplicate PUBLISH messages.  

It seems like when sending a PUBACK, the call to sendPacket should be given a separate timer rather than whatever time happens to be left in the yield() timer to make sure the PUBACK has enough time to actually be sent.  Or is there another way to deal with this scenario that I'm not seeing?  

--
Joe



Back to the top