mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-30 10:48:06 +02:00
Merge branch 'feature/support_no_keepalive' into 'master'
mqtt_config: Add config value to disable keepalive mechanism See merge request espressif/esp-mqtt!83
This commit is contained in:
@ -199,6 +199,7 @@ typedef struct {
|
|||||||
bool use_secure_element; /*!< enable secure element for enabling SSL connection */
|
bool use_secure_element; /*!< enable secure element for enabling SSL connection */
|
||||||
void *ds_data; /*!< carrier of handle for digital signature parameters */
|
void *ds_data; /*!< carrier of handle for digital signature parameters */
|
||||||
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
|
int network_timeout_ms; /*!< Abort network operation if it is not completed after this value, in milliseconds (defaults to 10s) */
|
||||||
|
bool disable_keepalive; /*!< Set disable_keepalive=true to turn off keep-alive mechanism, false by default (keepalive is active by default). Note: setting the config value `keepalive` to `0` doesn't disable keepalive feature, but uses a default keepalive period */
|
||||||
} esp_mqtt_client_config_t;
|
} esp_mqtt_client_config_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ typedef struct mqtt_connect_info {
|
|||||||
char *password;
|
char *password;
|
||||||
char *will_topic;
|
char *will_topic;
|
||||||
char *will_message;
|
char *will_message;
|
||||||
int keepalive;
|
int keepalive; // keepalive=0 -> keepalive is disabled
|
||||||
int will_length;
|
int will_length;
|
||||||
int will_qos;
|
int will_qos;
|
||||||
int will_retain;
|
int will_retain;
|
||||||
|
@ -419,6 +419,12 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
|
|||||||
if (client->connect_info.keepalive == 0) {
|
if (client->connect_info.keepalive == 0) {
|
||||||
client->connect_info.keepalive = MQTT_KEEPALIVE_TICK;
|
client->connect_info.keepalive = MQTT_KEEPALIVE_TICK;
|
||||||
}
|
}
|
||||||
|
if (config->disable_keepalive) {
|
||||||
|
// internal `keepalive` value (in connect_info) is in line with 3.1.2.10 Keep Alive from mqtt spec:
|
||||||
|
// * keepalive=0: Keep alive mechanism disabled (server not to disconnect the client on its inactivity)
|
||||||
|
// * period in seconds to send a Control packet if inactive
|
||||||
|
client->connect_info.keepalive = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (config->protocol_ver) {
|
if (config->protocol_ver) {
|
||||||
client->connect_info.protocol_ver = config->protocol_ver;
|
client->connect_info.protocol_ver = config->protocol_ver;
|
||||||
@ -1376,7 +1382,8 @@ static void esp_mqtt_task(void *pv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (platform_tick_get_ms() - client->keepalive_tick > client->connect_info.keepalive * 1000 / 2) {
|
if (client->connect_info.keepalive && // connect_info.keepalive=0 means that the keepslive is disabled
|
||||||
|
platform_tick_get_ms() - client->keepalive_tick > client->connect_info.keepalive * 1000 / 2) {
|
||||||
//No ping resp from last ping => Disconnected
|
//No ping resp from last ping => Disconnected
|
||||||
if (client->wait_for_ping_resp) {
|
if (client->wait_for_ping_resp) {
|
||||||
ESP_LOGE(TAG, "No PING_RESP, disconnected");
|
ESP_LOGE(TAG, "No PING_RESP, disconnected");
|
||||||
|
Reference in New Issue
Block a user