MQTT5 last will message

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

MQTT5 last will message

Postby zazas321 » Fri Apr 28, 2023 10:40 am

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?

ESP_Sprite
Posts: 9778
Joined: Thu Nov 26, 2015 4:08 am

Re: MQTT5 last will message

Postby ESP_Sprite » Sat Apr 29, 2023 4:14 am

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.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: MQTT5 last will message

Postby zazas321 » Tue May 02, 2023 4:55 am

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

integer_32
Posts: 1
Joined: Fri May 10, 2024 1:52 pm

Re: MQTT5 last will message

Postby integer_32 » Fri May 10, 2024 1:56 pm

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.

Who is online

Users browsing this forum: Google [Bot] and 80 guests