8 years, 10 months ago.

MQTT Client reconnection: message Handler being called multiple times

Hi All,

I am using the U-blox C027 kit and programming it to be a MQTT client that publishes to one topic and subscribes to another. It works fine, and messages are sent and received as expected. However, if the client is disconnected unexpectedly, things get a little complicated...

I use the isConnected() function to check if the client has disconnected, reinitialize ipstack and client, and reconnect with the same clientID. Then I re-subscribe to the same topic as before and resume publishing. The publishing part works fine, but for the subscription part: when a new message is received, the messageArrived() function is called twice in succession, and the payload in the second call is only the first character of the actual message (payload in the first call is correct).

If there is another disconnection and reconnection, the same process repeats and the messageArrived() function is now called 3 times. The payload in the last 2 calls now contains only the first character of the actual message.

Please advise if this is a bug in the library, or if I may be doing something wrong.

Question relating to:

Deprecated This team is no longer maintained, please use: https://github.com/ARMmbed/mbed-mqtt instead.

I think this sounds like a bug in the library. What QoS are you using?

posted by Ian Craggs 22 Jun 2015

I'm using QoS0 now. The disconnection only seems to happen when QoS1 or QoS2 messages are received (it's random, sometimes they are received correctly; sometimes they cause a disconnection). I haven't observed any automatic disconnection while using QoS0.

Another thing: when I use QoS1, I receive many duplicate messages (as expected). However, even QoS2 shows the same behaviour. I'm guessing there is some problem in sending the acknowledgement

posted by Farzan Hasani 23 Jun 2015
Be the first to answer this question.