Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The messages are lost #295

Open
sigmashig opened this issue Apr 30, 2023 · 3 comments
Open

The messages are lost #295

sigmashig opened this issue Apr 30, 2023 · 3 comments

Comments

@sigmashig
Copy link

sigmashig commented Apr 30, 2023

I'm using AsyncMqttClient on ESP32 + Ardion-ESP. I found, that a lot of messages are lost. I would try to describe a problem:

  1. After establishing the connection, I subscribe to 25 topics.
  2. MQTT server is configured as 'Publish the last message on subscribe in 1000ms'. And I see in the server log, that message is really sent:
2023-04-30 08:24:18.155 - info: mqtt.0 (6565) Client [Board_7] subscribes on "mqtt.0.HeatPump.Board_7.Config.SSID"
2023-04-30 08:24:18.188 - info: mqtt.0 (6565) Client [Board_7] publishOnSubscribe

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.

@nanobrad
Copy link

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.

@bertmelis
Copy link
Contributor

Two principles here:

  • the publisher defines the QoS of a message (the publisher is not aware of subscribers)
  • a subscriber defines the maximum QoS he wants to receive (or able to).

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.

@jbaudoux
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants