Closed sl2121 closed 1 year ago
Hi @sl2121, could you share the logs for the failed connection?
I have started from the sntp example and i continued with part of the the mqtt example. What is the meaning of : esp-tls-mbedtls: Certificate verified. Is that the esp has verified that the certificate is correct ? Or is the answer of the server?
Operating System: windows 10 Java Runtime Version: 17.0.4.1+1 Eclipse Version: 4.24.0.v20220607-0700 Eclipse CDT Version: 10.7.0.202204131742 IDF Eclipse Plugin Version: 2.6.0.202208110735 ESP-IDF v4.4.1-dirty Python set for IDF_PYTHON_ENV: Python 3.10.4
Thanks.
[0;32mI (17122) MQTTS_EXAMPLE: Other event id:7[0m [0;31mE (23882) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x7080[0m [0;32mI (23892) esp-tls-mbedtls: Certificate verified.[0m [0;31mE (23892) esp-tls: Failed to open new connection[0m [0;31mE (23892) TRANSPORT_BASE: Failed to open a new connection[0m [0;31mE (23902) MQTT_CLIENT: Error transport connect[0m [0;32mI (23902) MQTTS_EXAMPLE: MQTT_EVENT_ERROR[0m [0;32mI (23912) MQTTS_EXAMPLE: Last error code reported from esp-tls: 0x801a[0m [0;32mI (23922) MQTTS_EXAMPLE: Last tls stack error number: 0x7080[0m [0;32mI (23922) MQTTS_EXAMPLE: Last captured errno : 0 (Success)[0m [0;32mI (23932) MQTTS_EXAMPLE: MQTT_EVENT_DISCONNECTED[0m
hi i have loaded the ESP-MQTT SSL Sample application.
static void mqtt_app_start(void) { const esp_mqtt_client_config_t mqtt_cfg = { .uri = CONFIG_BROKER_URI, .cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start, }; mqtt_eclipseprojects_io_pem_start inside here i have put the DigiCertGlobalRootG2[] "MIIDjjCCAn...MrY" and also i have tried with the AWS Amazon Root CA1.
and i see :
[0;32mI (6592) example_connect: Got IPv4 event: Interface "example_connect: sta" address: * [0;32mI (6602) example_connect: Connected to example_connect: sta[0m [0;32mI (6612) example_connect: - IPv4 address: *** [0;32mI (6612) example_connect: - IPv6 address: f****, type: ESP_IP6_ADDR_IS_LINK_LOCAL[0m [0;32mI (6622) MQTTS_EXAMPLE: [APP] Free memory: 234100 bytes[0m [0;32mI (6632) MQTTS_EXAMPLE: Other event id:7[0m [0;32mI (15212) MQTTS_EXAMPLE: MQTT_EVENT_CONNECTED[0m [0;32mI (15222) MQTTS_EXAMPLE: sent subscribe successful, msg_id=53250[0m [0;32mI (15222) MQTTS_EXAMPLE: sent subscribe successful, msg_id=60112[0m [0;32mI (15222) MQTTS_EXAMPLE: sent unsubscribe successful, msg_id=18944[0m [0;32mI (15422) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=53250[0m [0;32mI (15432) MQTTS_EXAMPLE: sent publish successful, msg_id=0[0m [0;32mI (15472) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=60112[0m [0;32mI (15482) MQTTS_EXAMPLE: sent publish successful, msg_id=0[0m [0;32mI (15632) MQTTS_EXAMPLE: MQTT_EVENT_DATA[0m TOPIC=/topic/qos1 DATA=data_3
After in the static void mqtt_app_start(void) { const esp_mqtt_client_config_t mqtt_cfg = { .uri = "mqtts://miothub.azure-devices.net:8883", .cert_pem = (const char *)mqtt_eclipseprojects_io_pem_start, };
i see
[0;32mI (6612) example_connect: - IPv4 address: * [0;32mI (6612) example_connect: - IPv6 address: *****, type: ESP_IP6_ADDR_IS_LINK_LOCAL[0m [0;32mI (6622) MQTTS_EXAMPLE: [APP] Free memory: 234100 bytes[0m [0;32mI (6632) MQTTS_EXAMPLE: Other event id:7[0m [0;33mW (23892) esp-tls: Failed to open new connection in specified timeout[0m [0;31mE (23892) TRANSPORT_BASE: Failed to open a new connection[0m [0;31mE (23892) MQTT_CLIENT: Error transport connect[0m [0;32mI (23892) MQTTS_EXAMPLE: MQTT_EVENT_ERROR[0m [0;32mI (23902) MQTTS_EXAMPLE: Last error code reported from esp-tls: 0x8006[0m [0;32mI (23912) MQTTS_EXAMPLE: Last tls stack error number: 0x0[0m [0;32mI (23912) MQTTS_EXAMPLE: Last captured errno : 0 (Success)[0m [0;32mI (23922) MQTTS_EXAMPLE: MQTT_EVENT_DISCONNECTED[0m [0;32mI (38922) MQTTS_EXAMPLE: Other event id:7[0m [0;33mW (55842) esp-tls: Failed to open new connection in specified timeout[0m [0;31mE (55842) TRANSPORT_BASE: Failed to open a new connection[0m [0;31mE (55842) MQTT_CLIENT: Error transport connect[0m [0;32mI (55842) MQTTS_EXAMPLE: MQTT_EVENT_ERROR[0m [0;32mI (55852) MQTTS_EXAMPLE: Last error code reported from esp-tls: 0x8006[0m [0;32mI (55852) MQTTS_EXAMPLE: Last tls stack error number: 0x0[0m [0;32mI (55862) MQTTS_EXAMPLE: Last captured errno : 0 (Success)[0m [0;32mI (55872) MQTTS_EXAMPLE: MQTT_EVENT_DISCONNECTED[0m [0;32mI (70872) MQTTS_EXAMPLE: Other event id:7[0m
Thanks.
Hi @sl2121, check the error codes reported from esp-tls to identify the issue reported in the connection.
You may also want to check Azure Iot Hub side because this seems to be an authentication issue. They had a console application that you may use to monitor and debug this type of issues, unfortunately I don't remember the name of it. I recommend that you double-check your device credentials configuration.
From the perspective of esp-mqtt
the configuration you show have the needed data, so I would say, from the information you gave, that the issue is having the correct configuration in the IoT hub side.
Thanks for reporting, will close due to short of feedback, feel free to reopen with more updates. Thanks.
hi, i would like help on how connect to the azure iot hub withe "mqtt_client" library.
my configuration is the following :
static const unsigned char DigiCertGlobalRootG2[] = ( "-----BEGIN CERTIFICATE-----\r\n" "MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\r\n" "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\r\n" "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH\r\n" "MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT\r\n" "MRUwEwYDV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FICATE-----\r\n" );
const esp_mqtt_client_config_t mqtt_cfg = {
esp_err_t err; 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); err = esp_mqtt_client_start(client); ESP_LOGI (TAG, "Client connect. Error = %d %s", err, esp_err_to_name (err));
With these settings i can't connect. Thanks