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

check retained flag on received message #334

Open
lucabuka opened this issue Sep 23, 2024 · 1 comment
Open

check retained flag on received message #334

lucabuka opened this issue Sep 23, 2024 · 1 comment

Comments

@lucabuka
Copy link

Hi, first of all thanks for the great lib.
I'm trying to find a way to check if the received message have the Retained Flag set.
In other words i need to recognize if the received message is a retained message or a standard (not retained) one.
I've check onMessageAdvanced() but i don't see a way to get the information i need.

Am i missing something or actually this information is not available via the callback method ?
TIA

@lucabuka
Copy link
Author

lucabuka commented Sep 23, 2024

After checking the src files i can confirm the 'retained' flag of the incoming message is not returned by onMessage() or onMessageAdvanced.
In source file MQTTClient.cpp the function MQTTClientHandler() receives a lwmqtt_message_t parameter.
This struct, defined in lwmqtt/lwmqtt.h contains the retained message flag:

typedef struct {
  lwmqtt_qos_t qos;
  bool retained;
  uint8_t *payload;
  size_t payload_len;
} lwmqtt_message_t;

but this bool value is not managed in the AdvancedCallback:

typedef void (*MQTTClientCallbackAdvanced)(MQTTClient *client, char topic[], char bytes[], int length);

--

So i modified the library adding new callback function (MQTTClient.cpp, MQTTClient.h) :**

void onMessageDetailed(MQTTClientCallbackDetailedFunction cb);
// Callback signature: std::function<void(MQTTClient *client, char topic[], char bytes[], int length, bool retained, lwmqtt_qos_t qos )>

This way i now have available the message "retained" flag and there are no compatibility issues with my other sources using the Advanced Callback.

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

1 participant