pubsubclient
pubsubclient copied to clipboard
Multiple unsubscribe or publish with QoS 1 in callback
A ESP8266 client is subscribed to 9 topics (all retained messages). In callback are 9 if statements that are handling the received messages. After connection is established and callback function is set, ESP get stuck in callback function (and newer gets out) under certain conditions: Case 1: If statement for the first four or more topics: when a message on a topic is received, the client unsubscribes from the topic. Case 2: If statement for the last seven or more topics: when a message on a topic is received, the client unsubscribes from the topic. Case 3: If statement for the first four or more topics: when a message on a topic is received, the client publishes a message to another topic with QoS 1 (works with QoS 0). Case 4: If statement for the last seven or more topics: when a message on a topic is received, the client publishes a message to another topic with QoS 1 (works with QoS 0).
It’s a bit complicated but I hope you can get the point.
Unsubscribe is done as follows: MQTTclient.unsubscribe(MQTT::Unsubscribe().add_topic(pub.topic()));
And publish: MQTTclient.publish(MQTT::Publish(topic, payload) //(String topic, String payload) .set_retain() // Set retain flag .set_qos(qos) // (0-2) Set QoS value );
Could you help me with the issue?
can you please share your complete callback function code?