Imroy / pubsubclient

A client library for the ESP8266 that provides support for MQTT
MIT License
433 stars 115 forks source link

Multiple unsubscribe or publish with QoS 1 in callback #80

Open jreber2 opened 7 years ago

jreber2 commented 7 years ago

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?

amrithmmh commented 5 years ago

can you please share your complete callback function code?