arduino-mqtt
arduino-mqtt copied to clipboard
check retained flag on received message
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
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.