Chapter 4. Software framework
How should I configure the MQTT keepalive time when ESP32 Wi-Fi and Bluetooth LE coexist? Is there
any appropriate configuration time?
• When using Wi-Fi and Bluetooth LE concurrently in ESP32, it is recommended to configure the MQTT
keepalive time properly. Since both Wi-Fi and Bluetooth LE require system resources, setting the keepalive
time too short may cause high system load, affecting system stability and performance.
• Generally, it is advisable to set the MQTT keepalive time based on actual needs to ensure the device stays
online while minimizing system resource consumption. In the case of Wi-Fi and Bluetooth LE coexistence, it
is recommended to set the MQTT keepalive time to a longer duration, such as 30 seconds or 60 seconds, to
reduce communication between the device and the MQTT broker, thereby reducing system load.
• It is important to note that setting the keepalive time too long may cause a delay in detecting the device offline
when it disconnects, which may affect real-time performance and reliability. Therefore, the MQTT keepalive
time should be set based on actual needs and system performance.
When will the disconnect event message be triggered for ESP-MQTT clients?
The disconnect message only occurs in the follow cases:
• A TCP connection error occurs while the MQTT connection is being established.
• An MQTT connection error occurs while the MQTT connection is being established.
• You actively call the disconnect function.
• An exception is received or sent.
• The MQTT PING RESPONSE is not received within the specified time.
• The MQTT PING request failed to be sent.
• Reconnection.
Does the ESP32 MQTT client automatically try to reconnect after disconnecting from the server?
The esp_mqtt_client_config_t structure in the ESP-MQTT client has the dis-
able_auto_reconnect parameter, which can be configured as true or false to determine
to reconnect or not. By default, it will reconnect.
How to check if the ESP32 is disconnected from the MQTT server?
To detect if the ESP32 has been disconnected from the server, you can use MQTT's PING mech-
anism by configuring the keepalive parameters disable_keepalive and keepalive in the
esp_mqtt_client_config_t structure in ESP-MQTT. For example, if you configure dis-
able_keepalive to false (default setting) and keepalive to 120 s (default setting), the MQTT
client will periodically send PING to check if the connection to the server is working.
4.5.6 Other Protocols
How to optimize communication latency for ESP32?
• It
is
recommended
esp_wifi_set_ps(WIFI_PS_NONE).
• You can also disable the AMPDU function in menuconfig.
Espressif Systems
to
turn
off
the
sleep
102
Submit Document Feedback
function
for
Wi-Fi
by
calling
the
API
Release master
Need help?
Do you have a question about the ESP and is the answer not in the manual?