Chapter 2. API Reference
Functions
esp_mqtt_client_handle_t esp_mqtt_client_init(const esp_mqtt_client_config_t *config)
Creates mqtt client handle based on the configuration.
Return mqtt_client_handle if successfully created, NULL on error
Parameters
• config: mqtt configuration structure
esp_err_t esp_mqtt_client_set_uri(esp_mqtt_client_handle_t client, const char *uri)
Sets mqtt connection URI. This API is usually used to overrides the URI configured in esp_mqtt_client_init.
Return ESP_FAIL if URI parse error, ESP_OK on success
Parameters
• client: mqtt client handle
• uri:
esp_err_t esp_mqtt_client_start(esp_mqtt_client_handle_t client)
Starts mqtt client with already created client handle.
Return ESP_OK on success ESP_ERR_INVALID_ARG on wrong initialization ESP_FAIL on other error
Parameters
• client: mqtt client handle
esp_err_t esp_mqtt_client_reconnect(esp_mqtt_client_handle_t client)
This api is typically used to force reconnection upon a specific event.
Return ESP_OK on success ESP_ERR_INVALID_ARG on wrong initialization ESP_FAIL if client is in
invalid state
Parameters
• client: mqtt client handle
esp_err_t esp_mqtt_client_disconnect(esp_mqtt_client_handle_t client)
This api is typically used to force disconnection from the broker.
Return ESP_OK on success ESP_ERR_INVALID_ARG on wrong initialization
Parameters
• client: mqtt client handle
esp_err_t esp_mqtt_client_stop(esp_mqtt_client_handle_t client)
Stops mqtt client tasks.
• Notes:
• Cannot be called from the mqtt event handler
Return ESP_OK on success ESP_ERR_INVALID_ARG on wrong initialization ESP_FAIL if client is in
invalid state
Parameters
• client: mqtt client handle
int esp_mqtt_client_subscribe(esp_mqtt_client_handle_t client, const char *topic, int qos)
Subscribe the client to defined topic with defined qos.
Notes:
• Client must be connected to send subscribe message
• This API is could be executed from a user task or from a mqtt event callback i.e. internal mqtt task (API
is protected by internal mutex, so it might block if a longer data receive operation is in progress.
Return message_id of the subscribe message on success -1 on failure
Parameters
• client: mqtt client handle
• topic:
• qos:
int esp_mqtt_client_unsubscribe(esp_mqtt_client_handle_t client, const char *topic)
Unsubscribe the client from defined topic.
Notes:
Espressif Systems 511
Submit Document Feedback
Release v4.4