pubsubclient
pubsubclient copied to clipboard
Problem with subscribe ESP got hang
Hello I have problem with subscribe when it received data from subscribe.
if(mqtt_connected) {
client.subscribe("topic/setting/+")
// payload will be `topica/a`
}
void callback(const MQTT::Publish& pub) {
String topic = pub.topic();
String data = pub.payload_string();
// I cut string with `setting` on topic
if (receive topic == "setting") {
client.subscribe(payload);
}
}
and I use client to subscribe with retained like.
topic = topic/setting/1
payload = topica/a
retained
topic = topic/setting/2
payload = topicb/b
retained
// so when esp boot it will be 3 subscribe
// 1.topic/setting/+
this 2 will subscribe in if condition.
// 2.topica/a
// 3.topicb/b
NOW I got esp hang. if I set retain more than one topic.
but If I use retain with one topic like.
topic = topic/setting/1
payload = topica/a
retained
my esp not hang.
don't know what the problem are.