MQTT Connection delay

I run a ESP8266 that send out a door state (open ,close) before going to deep sleep for a while.
Since it is powered by a battery I want to by as quick as possible to connect + send MQTT message.

I made some (very stable) mesurements (wake-up & sending frequence = 1 minute) :

Mosquitto broker configuration : version: 5.1.1
Plateform : raspi3
Core : core-2021.4.6

image

  • before_mqtt : 74 ms to connect to WIFI
  • awake time : Total awake time : 596 ms including MQTTbroker connection and sending

That means

  • 74ms to connect to WIFI (excellent)
  • 500ms+ to make the connection which is a huge delay compare to WIFI connection.

Do you have ideas where this delay comes from ?
I’ll make some additionnal tests with a stand alone MQTT brocker installed on my lap top…

By pushing my investigations I noticed that every 5 minutes (every 6 sending) the MQTT connection & sending takes not 500 ms but almost 2 sec where as the WIFI connection delay stays inchanged.

Did you have a similar issue on Mosquitto brocker connection ?

Here the screenshots :

Thiis is the root cause:

The solution is to upgrade to v6.0.1 (most recent) or downgrade to v5.1

Hello and thank you Maxym

I made 2 investigations :slight_smile:

  • MQTT version update to V6.0.1
    Unfortunately no improvement with the version update but non additionnal delay afer 5mn.
    So slight improvement…
{"device":4,"door_state":"close","Vbatt":3331,"before_mqtt":76,"awake_time":597}
  • Mosquitto brocker on my lap top
    Same behavior except no additionnal delay after 5mn
{"device":4,"door_state":"close","Vbatt":3355,"before_mqtt":77,"awake_time":600}

So I’ll focus to my c++

After some software improvement, I finally achieve to reduce significatly the connection delay

image

I finally get 254 ms to connect to wifi, connect to MQTT brocker, send payload and return to deep sleep which is really excellent.
That ensures years with one 18650 battery.