Failed Publish when subscribed to same topic as publisher?

Asked by Christopher

I am currently working on a embedded c project using mqtt 3.1.1 and mosquitto broker 1.4.5 the issue I have is when the client is publishing and subscribed to the same topic, after a random number of messages the client is blocked and the connection gets timed-out.

I am trying to send a string message, over 3G network. Using QOS2 on both pub & sub, I have tried different settings on the client for keepalive (15s <-> 120s) and have a delay between each message (2000ms <-> 300000ms), on the broker I have tried different settings also, but nothing seem to work, is it possible to send messages using QOS2 over a 3G network or am I expecting too much?

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

It sounds like you aren't calling the function required to process data in the background and so are being timed out. Is there an MQTTYield() function?

Revision history for this message
Christopher (cdonovan) said :
#2

Hi Roger, I am calling MqttYield() with a wait time of 200ms, is that short a time should I keep it the same as the keep alive time, or just less than it? It is a hardcoded value at the moment!

Revision history for this message
Christopher (cdonovan) said :
#3

Actually my last comment was a mistake, I am currently using:

if(c.isconnected){
    if (MQOS == 2)
      MQTTYield(&c, 2000);
    else
      MQTTYield(&c, 200);
  }

Revision history for this message
Roger Light (roger.light) said :
#4

I presume the timeout to MQTTYield is just how long it will wait for new data, I'm sure either of those values is fine.

How frequently are you calling MQTTYield is perhaps the better question.

Honestly this might be better on the Paho mailing list so you get more input that just me.

Revision history for this message
Christopher (cdonovan) said :
#5

I do call the MqttYield() before each publish:

Logic:

setPubFlag=1

checkMqtt(); // here the mqtt yield method is called

while (pubflag){
    setimer=delay;
    if (timer == 0)
    publish(msg)
}

will post on PAHO as well, thanks for the library and all the help.

Revision history for this message
Roger Light (roger.light) said :
#6

Right, so I'd suggest calling MQTTYield() frequently then. If it operates the same way as libmosquitto, that is the means that background network traffic is processed and so you need to keep on calling it.

Can you help with this problem?

Provide an answer of your own, or ask Christopher for more information if necessary.

To post a message you must log in.