PubSub publish() fail

Helo!

I'm using the PubSub library to post some messages within a for topic on some topics:

for (int i = 0; i<6; i++){
String msg = "Hello " + (String) i;
client.loop();
Serial.println(client.publish("teste/teste2", msg.c_str()));
delay(500)
}

But it turns out that some of these messages are not published, although the publish () function always returns true.

Has anyone ever experienced this? Do I need to increase the delay?

Is it your own broker? If so, try running it in verbose mode to see what's wrong. Otherwise, perhaps keep increasing the delay until the issue goes away.

Don't forget that it may be the receiver that can't keep up.

I use the mosquitto with username and password.

I put the keep alive for 90 seconds:

client.setKeepAlive(90);

and it worked, all messages were published.

But I'm not sure why it worked...

Hard to say without seeing all your code. Perhaps you're doing something else slow that times your connection out.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.