Page 1 of 1

MQTT5 last will message

Posted: Fri Apr 28, 2023 10:40 am
by zazas321
Hello. I use mqtt5 example from esp-idf.

Settings are set to the default values:

Code: Select all

        .session_expiry_interval = 10,
        .maximum_packet_size = 1024,
        .receive_maximum = 65535,
        .topic_alias_maximum = 2,
        .request_resp_info = true,
        .request_problem_info = true,
        .will_delay_interval = 10,
        
        .payload_format_indicator = true,
        .message_expiry_interval = 10,
        .response_topic = "/test/response",
        .correlation_data = "123456",
        .correlation_data_len = 6,
    };

    esp_mqtt_client_config_t mqtt5_cfg = {
        .broker.address.uri = CONFIG_BROKER_URL,
        .session.protocol_ver = MQTT_PROTOCOL_V_5,
        .network.disable_auto_reconnect = true,
        .credentials.username = "123",
        .credentials.authentication.password = "456",
        .session.last_will.topic = "/topic/will",
        .session.last_will.msg = "i will leave",
        .session.last_will.msg_len = 12,
        .session.last_will.qos = 1,
        .session.last_will.retain = false,
    };
    
I am not fully understanding which settings control when the last will message will be sent?

The settings that I am concerned about:

.session_expiry_interval = 10,
What does session expiry mean? How does it affect last will?

.will_delay_interval = 10,
Does that mean that will message will be sent 10 seconds after disconnecting?


The reason I ask this is because on my mqtt broker, I receive last will message 3 minutes after device is disconnected. Why 3 minutes? How to change that time?

Re: MQTT5 last will message

Posted: Sat Apr 29, 2023 4:14 am
by ESP_Sprite
A last will message is not something that gets sent at the moment the ESP disconnect. The last will message is something that is sent to the MQTT broker on connection, and the MQTT broker will execute it as soon as it detects a disconnect. When the broker detects a disconnect depends on the broker, the OS it runs on, etc.

Re: MQTT5 last will message

Posted: Tue May 02, 2023 4:55 am
by zazas321
Thanks for clarification.

Are you suggesting that there are no standard parameters that control when the message will be executed?

I am not sure if that is official but I have found somewhere, that the will message will be executed after:

(1.5 x * keep_alive_interval) + will_delay_interval

Re: MQTT5 last will message

Posted: Fri May 10, 2024 1:56 pm
by integer_32
I'm having the same problem.
I'm running mosquitto in Docker on Debian in the same local network.
I have multiple clients - paho in python, hivemq in kotlin, and if I cut power from those devices (so it's not a "graceful" connection termination), broker detects it immediately.
But not for ESP32 - in this case it takes few minutes to detect disconnection. Wondering what's the difference between them.