Merge branch 'feature/update_mqtt_client' into 'master'

[MQTT] - Updates esp_mqtt configuration struct

See merge request espressif/esp-idf!18101
This commit is contained in:
David Čermák
2022-07-20 19:52:04 +08:00
20 changed files with 221 additions and 152 deletions

View File

@@ -355,7 +355,7 @@ def test_app_protocol_mqtt_publish_connect(env, extra_data):
return None, None
return value.group(1), int(value.group(2))
publish_cfg['publish_topic'] = dut1.app.get_sdkconfig()['CONFIG_EXAMPLE_SUBSCIBE_TOPIC'].replace('"','')
publish_cfg['publish_topic'] = dut1.app.get_sdkconfig()['CONFIG_EXAMPLE_SUBSCRIBE_TOPIC'].replace('"','')
publish_cfg['subscribe_topic'] = dut1.app.get_sdkconfig()['CONFIG_EXAMPLE_PUBLISH_TOPIC'].replace('"','')
publish_cfg['broker_host_ssl'], publish_cfg['broker_port_ssl'] = get_host_port_from_dut(dut1, 'CONFIG_EXAMPLE_BROKER_SSL_URI')
publish_cfg['broker_host_tcp'], publish_cfg['broker_port_tcp'] = get_host_port_from_dut(dut1, 'CONFIG_EXAMPLE_BROKER_TCP_URI')

View File

@@ -30,7 +30,7 @@ menu "Example Configuration"
help
topic to which esp32 client publishes
config EXAMPLE_SUBSCIBE_TOPIC
config EXAMPLE_SUBSCRIBE_TOPIC
string "subscribe topic"
default "/topic/subscribe/py2esp"
help

View File

@@ -64,7 +64,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
static void create_client(void)
{
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtts://127.0.0.1:1234"
.broker.address.uri = "mqtts://127.0.0.1:1234"
};
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_register_event(client, ESP_EVENT_ANY_ID, mqtt_event_handler, client);
@@ -88,7 +88,7 @@ static void connect_no_certs(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri
.broker.address.uri = uri
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -100,12 +100,12 @@ static void connect_with_client_key_password(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)ca_local_crt,
.client_cert_pem = (const char *)client_pwd_crt,
.client_key_pem = (const char *)client_pwd_key,
.clientkey_password = "esp32",
.clientkey_password_len = 5
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)ca_local_crt,
.credentials.authentication.certificate = (const char *)client_pwd_crt,
.credentials.authentication.key = (const char *)client_pwd_key,
.credentials.authentication.key_password = "esp32",
.credentials.authentication.key_password_len = 5
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -117,11 +117,11 @@ static void connect_with_server_der_cert(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)ca_der_start,
.cert_len = ca_der_end - ca_der_start,
.client_cert_pem = "NULL",
.client_key_pem = "NULL"
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)ca_der_start,
.broker.verification.certificate_len = ca_der_end - ca_der_start,
.credentials.authentication.certificate = "NULL",
.credentials.authentication.key = "NULL"
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -133,10 +133,10 @@ static void connect_with_wrong_server_cert(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)client_pwd_crt,
.client_cert_pem = "NULL",
.client_key_pem = "NULL"
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)client_pwd_crt,
.credentials.authentication.certificate = "NULL",
.credentials.authentication.key = "NULL"
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -148,8 +148,8 @@ static void connect_with_server_cert(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)ca_local_crt,
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)ca_local_crt,
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -161,10 +161,10 @@ static void connect_with_server_client_certs(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)ca_local_crt,
.client_cert_pem = (const char *)client_pwd_crt,
.client_key_pem = (const char *)client_no_pwd_key
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)ca_local_crt,
.credentials.authentication.certificate = (const char *)client_pwd_crt,
.credentials.authentication.key = (const char *)client_no_pwd_key
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -176,10 +176,10 @@ static void connect_with_invalid_client_certs(const char *host, const int port)
char uri[64];
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.cert_pem = (const char *)ca_local_crt,
.client_cert_pem = (const char *)client_inv_crt,
.client_key_pem = (const char *)client_no_pwd_key
.broker.address.uri = uri,
.broker.verification.certificate = (const char *)ca_local_crt,
.credentials.authentication.certificate = (const char *)client_inv_crt,
.credentials.authentication.key = (const char *)client_no_pwd_key
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);
@@ -192,8 +192,8 @@ static void connect_with_alpn(const char *host, const int port)
const char *alpn_protos[] = { "mymqtt", NULL };
sprintf(uri, "mqtts://%s:%d", host, port);
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = uri,
.alpn_protos = alpn_protos
.broker.address.uri = uri,
.broker.verification.alpn_protos = alpn_protos
};
esp_mqtt_set_config(mqtt_client, &mqtt_cfg);
esp_mqtt_client_disconnect(mqtt_client);

View File

@@ -52,8 +52,8 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
xEventGroupSetBits(mqtt_event_group, CONNECTED_BIT);
msg_id = esp_mqtt_client_subscribe(client, CONFIG_EXAMPLE_SUBSCIBE_TOPIC, qos_test);
ESP_LOGI(TAG, "sent subscribe successful %s , msg_id=%d", CONFIG_EXAMPLE_SUBSCIBE_TOPIC, msg_id);
msg_id = esp_mqtt_client_subscribe(client, CONFIG_EXAMPLE_SUBSCRIBE_TOPIC, qos_test);
ESP_LOGI(TAG, "sent subscribe successful %s , msg_id=%d", CONFIG_EXAMPLE_SUBSCRIBE_TOPIC, msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
@@ -164,24 +164,24 @@ static void configure_client(char *transport)
break;
case TCP:
ESP_LOGI(TAG, "[TCP transport] Startup..");
config.uri = CONFIG_EXAMPLE_BROKER_TCP_URI;
config.broker.address.uri = CONFIG_EXAMPLE_BROKER_TCP_URI;
break;
case SSL:
ESP_LOGI(TAG, "[SSL transport] Startup..");
config.uri = CONFIG_EXAMPLE_BROKER_SSL_URI;
config.broker.address.uri = CONFIG_EXAMPLE_BROKER_SSL_URI;
break;
case WS:
ESP_LOGI(TAG, "[WS transport] Startup..");
config.uri = CONFIG_EXAMPLE_BROKER_WS_URI;
config.broker.address.uri = CONFIG_EXAMPLE_BROKER_WS_URI;
break;
case WSS:
ESP_LOGI(TAG, "[WSS transport] Startup..");
config.uri = CONFIG_EXAMPLE_BROKER_WSS_URI;
config.broker.address.uri = CONFIG_EXAMPLE_BROKER_WSS_URI;
break;
}
if (selected_transport == SSL || selected_transport == WSS) {
ESP_LOGI(TAG, "Set certificate");
config.cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start;
config.broker.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start;
}
esp_mqtt_set_config(mqtt_client, &config);