hirotakaster / MQTT

MQTT for Photon, Spark Core
Other
216 stars 118 forks source link

Subscribe Retain Flag #73

Open marc-gist opened 5 years ago

marc-gist commented 5 years ago

How can I check in the subscribe callback if the payload is a retained value?

Thanks,

hirotakaster commented 5 years ago

@marc-gist check the MQTT protocol and your MQTT broker server specifications. http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html

marc-gist commented 5 years ago

No, I mean in your code and on the Photon/Core.

i.e. my code:

void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;

    Serial.printlnf("Payload %s", p);
    if(!strcmp(p, "check")) {
        check_sensor();
    }

I can check the topic and payload, but how can I check the retained flag?

hirotakaster commented 5 years ago

Now my callback don't have a retain flag argument as you know. If you want to know the published message retain flag when your app first connect to the MQTT server, you could implements new callback method with checking the client.buffer mqtt header in loop() function.