- I (6413) MQTTS_EXAMPLE: Other event id:7
- I (7293) MQTTS_EXAMPLE: MQTT_EVENT_CONNECTED
- I (7293) MQTTS_EXAMPLE: sent subscribe successful, msg_id=45317
- I (7293) MQTTS_EXAMPLE: sent subscribe successful, msg_id=37869
- I (7293) MQTTS_EXAMPLE: sent unsubscribe successful, msg_id=20820
- I (7323) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=45317
- I (7323) MQTTS_EXAMPLE: sent publish successful, msg_id=0
- I (7363) MQTTS_EXAMPLE: MQTT_EVENT_SUBSCRIBED, msg_id=37869
- I (7363) MQTTS_EXAMPLE: sent publish successful, msg_id=0
- I (7363) MQTTS_EXAMPLE: MQTT_EVENT_UNSUBSCRIBED, msg_id=20820
- E (12513) esp-tls-mbedtls: read error :-0x004C:
- E (12513) transport_base: esp_tls_conn_read error, errno=Socket is not connected
- E (12513) mqtt_client: esp_mqtt_handle_transport_read_error: transport_read() error: errno=128
- I (12523) MQTTS_EXAMPLE: MQTT_EVENT_ERROR
- I (12523) MQTTS_EXAMPLE: Last error code reported from esp-tls: 0x0
- I (12533) MQTTS_EXAMPLE: Last tls stack error number: 0x4c
- I (12543) MQTTS_EXAMPLE: Last captured errno : 0 (Success)
- E (12543) mqtt_client: mqtt_process_receive: mqtt_message_receive() returned -1
- I (12553) MQTTS_EXAMPLE: MQTT_EVENT_DISCONNECTED
I have done registration to DPS, procedure of refreshing SAS tokens and sending telemetry to IoT HUB. It worked for some time. After several days it stopped working. There was several failures. One success and then no more success.
I isolated problem by writing desktop Pyton script which is really bulletproof - every time sends telemtry properly. I use the same data: device id, username, password from Python code in my ESP-IDF C code. And cannot connect.
The minimal example is example of MQTT ssl with pem file from my Azure hostname, and credentials from Python script.
- const esp_mqtt_client_config_t mqtt_cfg = {
- .broker = {
- .address.uri = CONFIG_BROKER_URI,
- .verification.certificate = (const char *)broker_pem_start,
- },
- .session = {
- .keepalive = 240,
- .protocol_ver = MQTT_PROTOCOL_V_3_1_1
- },
- .credentials = {
- .client_id = "theendisreal_1",
- .username = "XXXXXXXXXXX.azure-devices.net/theendisreal_1/?api-version=2018-06-30",
- .authentication.password = "SharedAccessSignature sr=XXXXXXXXXXX.azure-devices.net%2Fdevices%2Ftheendisreal_1&sig=ZZZZZZZZZZZZZZZZ&se=1709043213"
- }
- };
- W (7383) mqtt_client: Connection refused, not authorized
- I (7383) MQTTS_EXAMPLE: MQTT_EVENT_ERROR
- I (7383) MQTTS_EXAMPLE: Connection refused error: 0x5
- E (6603) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x2700
- I (6603) esp-tls-mbedtls: Failed to verify peer certificate!
- E (6613) esp-tls: Failed to open new connection
- E (6613) transport_base: Failed to open a new connection
I know there is SDK for C, and example for FreeRTOS but to be honest, this code is a mess. And also had the same problem with thransport.
What could cause this error?