Open fsommer1968 opened 4 years ago
I was looking for the same question. It is currently not implemented in the PubSubClient
library, so I made a workaround outside the library:
const char MQTT_TOPIC_OUT[] PROGMEM = "outTopic";
const char MQTT_TOPIC_IN[] PROGMEM = "inTopic";
void mqttPublish()
{
char bufferOut[sizeof(MQTT_TOPIC_OUT)];
memcpy_P(bufferOut, MQTT_TOPIC_OUT, sizeof(MQTT_TOPIC_OUT));
client.publish(bufferOut, payload);
}
void mqttSubscribe()
{
char bufferIn[sizeof(MQTT_TOPIC_IN)];
memcpy_P(bufferIn, MQTT_TOPIC_IN, sizeof(MQTT_TOPIC_IN));
client.subscribe(bufferIn);
}
Same buffer copy can be done for payload.
Please note that publish_P()
is currently broken. See issue here: https://github.com/knolleary/pubsubclient/issues/747
As topics can be long (e.g. with Bluemix ;-) ), a subscribe function that allows the topic to be loaded from PROGMEM (similar to publish_P) would be helpful. Please check if this is possible.