I cannot publish any strings in variables anymore!
All worked fine for a year or so. Then I recompiled my sketch and it stopped working.
I can do client.publish("topic","Sometext"),
but not
char msg[] = "Sometext";
client.publish("topic",msg);
I see the definition of publish in the API documentation says you have to use const char[] As I am not a C programmer I don't really understand the fine meaning of that definition. But if I define the variable then it will give a compile error when I try to change that "variable" because it is readonly.
I found out that the MQTT_MAX_PACKET_SIZE variable was set too low. This has to be done in the PubSubClient.h file of the library, it cannot be redefinied in the Sketch!
See also https://gist.github.com/igrr/7f7e7973366fc01d6393 for the precise commands to publish a String and here you will find the statement of the builder of the lib what to do.
I tried char[10] = "abc";
it's ok , but not dynamic
incomming = .....
char charBuf[incoming.length() + 1];
incoming.toCharArray(charBuf,incoming.length() + 1);
client.publish(mqtt_topic_pub, charBuf);
Try it ^^
It works. Thank you!
Most helpful comment
incomming = .....
char charBuf[incoming.length() + 1];
incoming.toCharArray(charBuf,incoming.length() + 1);
client.publish(mqtt_topic_pub, charBuf);
Try it ^^