mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-07-30 10:48:06 +02:00
feat: Allow users to get the transport in use
This commit is contained in:
@ -29,6 +29,11 @@ typedef void *esp_event_handler_t;
|
||||
|
||||
typedef struct esp_mqtt_client *esp_mqtt_client_handle_t;
|
||||
|
||||
#define MQTT_OVER_TCP_SCHEME "mqtt"
|
||||
#define MQTT_OVER_SSL_SCHEME "mqtts"
|
||||
#define MQTT_OVER_WS_SCHEME "ws"
|
||||
#define MQTT_OVER_WSS_SCHEME "wss"
|
||||
|
||||
/**
|
||||
* @brief *MQTT* event types.
|
||||
*
|
||||
@ -661,6 +666,27 @@ int esp_mqtt_client_get_outbox_size(esp_mqtt_client_handle_t client);
|
||||
*/
|
||||
esp_err_t esp_mqtt_dispatch_custom_event(esp_mqtt_client_handle_t client, esp_mqtt_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Get a transport from the scheme
|
||||
*
|
||||
* Allows extra settings to be made on the selected transport,
|
||||
* for convenience the scheme used by the mqtt client are defined as
|
||||
* MQTT_OVER_TCP_SCHEME, MQTT_OVER_SSL_SCHEME, MQTT_OVER_WS_SCHEME and MQTT_OVER_WSS_SCHEME
|
||||
* If the transport_scheme is NULL and the client was set with a custom transport the custom transport will be returned.
|
||||
*
|
||||
* Notes:
|
||||
* - This function should be called only on MQTT_EVENT_BEFORE_CONNECT.
|
||||
* - The intetion is to provide a way to set different configurations than the ones available from client config.
|
||||
* - If esp_mqtt_client_destroy is called the returned pointer will be invalidated.
|
||||
* - All the required settings should be made in the MQTT_EVENT_BEFORE_CONNECT event handler
|
||||
*
|
||||
* @param client *MQTT* client handle
|
||||
* @param transport_scheme Transport handle to search for.
|
||||
* @return the transport handle
|
||||
* NULL in case of error
|
||||
*
|
||||
*/
|
||||
esp_transport_handle_t esp_mqtt_client_get_transport(esp_mqtt_client_handle_t client, char *transport_scheme);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif //__cplusplus
|
||||
|
@ -24,11 +24,6 @@ static const char *TAG = "mqtt_client";
|
||||
ESP_EVENT_DEFINE_BASE(MQTT_EVENTS);
|
||||
#endif
|
||||
|
||||
#define MQTT_OVER_TCP_SCHEME "mqtt"
|
||||
#define MQTT_OVER_SSL_SCHEME "mqtts"
|
||||
#define MQTT_OVER_WS_SCHEME "ws"
|
||||
#define MQTT_OVER_WSS_SCHEME "wss"
|
||||
|
||||
const static int STOPPED_BIT = (1 << 0);
|
||||
const static int RECONNECT_BIT = (1 << 1);
|
||||
const static int DISCONNECT_BIT = (1 << 2);
|
||||
@ -1587,9 +1582,6 @@ static void esp_mqtt_task(void *pv)
|
||||
break;
|
||||
case MQTT_STATE_INIT:
|
||||
xEventGroupClearBits(client->status_bits, RECONNECT_BIT | DISCONNECT_BIT);
|
||||
client->event.event_id = MQTT_EVENT_BEFORE_CONNECT;
|
||||
esp_mqtt_dispatch_event_with_msgid(client);
|
||||
|
||||
|
||||
client->transport = client->config->transport;
|
||||
if (!client->transport) {
|
||||
@ -1617,6 +1609,9 @@ static void esp_mqtt_task(void *pv)
|
||||
esp_mqtt_set_ssl_transport_properties(client->transport_list, client->config);
|
||||
#endif
|
||||
|
||||
client->event.event_id = MQTT_EVENT_BEFORE_CONNECT;
|
||||
esp_mqtt_dispatch_event_with_msgid(client);
|
||||
|
||||
if (esp_transport_connect(client->transport,
|
||||
client->config->host,
|
||||
client->config->port,
|
||||
@ -2282,3 +2277,13 @@ int esp_mqtt_client_get_outbox_size(esp_mqtt_client_handle_t client)
|
||||
|
||||
return outbox_size;
|
||||
}
|
||||
|
||||
esp_transport_handle_t esp_mqtt_client_get_transport(esp_mqtt_client_handle_t client, char *transport_scheme){
|
||||
if (client == NULL || (transport_scheme == NULL && client->config->transport == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
if (transport_scheme == NULL && client->config->transport != NULL) {
|
||||
return client->config->transport;
|
||||
}
|
||||
return esp_transport_list_get_transport(client->transport_list, transport_scheme);
|
||||
}
|
||||
|
Reference in New Issue
Block a user