[SOLVED] Fail to publish data but client.publish() returns 1?



I have an ESP32 device that publishes 4 data every 3 minutes, without any context.

In my loop function, the calls to the routine client.publish(…) always return 1, but when I look to the raw data in the graphical interface, I see that 2 variables are never updated. And when I modify my code so that only these 2 variables are published, then they are correctly updated…

What could cause a data not to be updated ? Is there a limit to the number of variables that can be published, other than the 60var/min limit ?

Many thanks for your help


Greetings, if you are using the PubSubclient, this library has 128 bytes as limit to publish data. You may modify that limit via MQTT_MAX_PACKET_SIZE in PubSubClient.h or to split your four variables in two different messages.

All the best


Hi Jose,

Yes, I do use PubSubClient.

I publish all the data individually, ie I execute 1 “client.publish(…)” command for each data.
For example:
/v1.6/devices/yves_esp32 {“tempchambre”: 10.0}
/v1.6/devices/yves_esp32 {“tempext”: 20.0}

I wonder about the client.loop() command. It seems to have an influence on the problem I am facing:
How often does this command need to be executed ? After any client.publish(…) ?
Is there a delay to respect before or after this commant is executed ?



According to the library docs:

boolean loop ()
This should be called regularly to allow the client to process incoming messages and maintain its connection to the ser

I usually execute the loop command at the end of the firmware routine, but it should not have any incidence for sending more or less values as always as it is executed at any time in the routine.

My advice is to take a look to the basic example from our docs and to adapt it to your needs.

All the best


I have inserted more calls to client.loop() in my code, one after each call to client.publish(). And it works fine now. So my problem is solved, although I don’t think I have fully understood it.
Thanks for your help