An API for using MQTT over multiple transports

Dependencies:   FP MQTTPacket

Dependents:   Cellular_HelloMQTT IoTStarterKit GSwifiInterface_HelloMQTT IBMIoTClientEthernetExample ... more

Issue: Yield(timeout) does not behave as documented

Hi,

I'm using the blocking MQTT client. After setting up the MQTT connection to the broker and subscribing to some topics, I call

int main(int argc, char* argv[]){

  ... 
  // initialise IPStack, MQTT and subscribe to topics 
  ...
  int rc; 
  while(true){
    rc = yield(100L);
    if(rc == -1)
      fprintf(stdout, "no packet received");
  }
}

in the Main Loop of my program.

The documentation describes the return parameter of yield as follows:

Quote:

@return success code - on failure, this means the client has disconnected

However, yield also returns failure (-1) when in the specific time period (timeout), no MQTT message has been received.

I can confirm that the client has definitely not disconnected, despite yield returning FAILURE. So therefor either the documentation is wrong, or (probably the better way), yield(timeout) should return SUCCESS, also when no packet has been received.

9 comments:

22 Feb 2016

Tobias, I think you are correct about this. Sorry for the delayed reply.

16 Feb 2017

Hello,

Even i am experiencing the same issue, is this issue resolved ?

cheers Rao

26 Mar 2017

I tried it today. Issue still persists.

04 May 2017

It works well with MBED version 2

However if you use MBED version 5 core you should to set your custom interface/class I/O functions as "non blocking".

10 Oct 2017

Hello Ian Craggs, is this normal, that Client.Yield is waiting until message will come and not for timeout?

I'm trying to send KeepAlive message (so MQTT Client won't disconnect from MQTT Server) every 2 seconds. But Yield does not timeout, instead it's waiting for new message. So after minute MQTT Client disconnects.

    while(1) {
        rc = client.publish(systemTopic, message);
        client.yield(2000);
    }

Thank you!

22 Mar 2018

I have the same problem. Find a solution to keep always active while waiting to receive. Thank you

25 Jun 2018

Hello, is there any new progress on this? If calling yield(...), the thread waits indefinitely. This means if no message arrives within a few minutes, the connection closes, because apparently no PINGREQ (keepalive) packets are sent (even if keepAliveInterval property is set in the connectData).

30 Oct 2018

Hi, I had similar issue. Using approach from MQTTSocket.h (handling socket timeouts manually) worked to me.

09 Jan 2021

Hello,is there a solution on this problem,the library works smooth but the yield problem persists.Mister Craggs we need your help.