Open sigmashig opened 1 year ago
The QoS value used during subscription is the highest QoS you will accept. Meaning, if you subscribe with QoS of 0, then you will not be sent messages published with a QoS of 1 or 2. This is part of the protocol.
Two principles here:
When a message is published, it travels to the broker with a certain QoS. The broker then distributes it to the subscribers and possibly downgrading the QoS to match the clients subscription. QoS is, however, not upgraded. So a message sent with qos 2 can end at a client with qos 0. A message with qos 0 will be received and qos 0, also when the subscription is made with qos 2.
I was facing similar issue and end-up on this thread. I'm subscribing to about 40 topics. Some topics where not receiving the messages.
I analyzed the broker log and spotted that not all subscriptions had been registered.
I solved the issue by calling yield()
every few subscription. I think you need to have the subscription in loop to have it working. Calling delay(10)
was also working.
I'm using AsyncMqttClient on ESP32 + Ardion-ESP. I found, that a lot of messages are lost. I would try to describe a problem:
On the client, I provide a callback function for onMessage with just one line: put received topic+message to the Serial for testing. I didn't get a lot of messages, but when I look at server log I see:
2023-04-30 08:24:18.403 - debug: mqtt.0 (6565) Client [Board_7] send to this client "HeatPump/Board_7/Config/SSID": deleted
As a result, I have got messages just for 4-5 topics from 25 subscriptions. What am I doing wrong? UPDATE: It happens when I run subscribe with QoS=2. I received all messages, when I subscribes with QoS=0. Why? I thought, that QoS=2 guarantees just that messages are delivered, but in real life it is not.