I am using AWS FreeRTOS 202002.00 and ESP32-DevKitC. I have configured the MQTT Demo and I downloaded the code to the chip. In the logs I see that it connect with my ESP32 connect using Wifi, it obtained an IP address and tried start to MQTT connection. But the MQTT connection respond the code -1002 (SOCKETS_TLS_HANDSHAKE_ERROR ( -1002 ) /*!< TLS handshake failed. ) immediately. I have made many changes (Increase Task Stack, Show Debug Logs, etc) but I didn’t found the cause of the problem. I remembered use a previous AWS FreeRTOS version and the demo worked in the past. I don’t understand because the default MQTT demo doesn’t work.
Thanks for all your support. I attach the logs. I remove my AWS IoT Endpoint for security.
I (5148) WIFI: SYSTEM_EVENT_STA_CONNECTED
4 601 [IP-task] vDHCPProcess: offer c0a80014ip
I (7388) event: sta ip: 192.168.0.20, mask: 255.255.255.0, gw: 192.168.0.1
I (7388) WIFI: SYSTEM_EVENT_STA_GOT_IP
5 709 [IP-task] vDHCPProcess: offer c0a80014ip
6 710 [iot_thread] [INFO ][DEMO] Successfully initialized the demo. Network type for the demo: 1
7 710 [iot_thread] [INFO ][MQTT] MQTT library successfully initialized.
8 710 [iot_thread] [INFO ][DEMO] MQTT demo client identifier is RemoteLogger (length 12).
9 716 [iot_thread] DNS[0x8CA8]: The answer to 'xxxxxx-ats.iot.us-east-1.amazonaws.com' (xxxxxxxxip) will be stored
10 744 [iot_thread] [ERROR][NET] Failed to establish new connection. Socket status: -1002.
11 744 [iot_thread] [ERROR][MQTT] Failed to establish new MQTT connection, error NETWORK ERROR.
12 744 [iot_thread] [ERROR][DEMO] MQTT CONNECT returned error NETWORK ERROR.
I (7758) wifi: state: run -> init (0)
I (7758) wifi: pm stop, total sleep time: 2060881 us / 2607097 us
I (7768) wifi: new:<9,0>, old:<9,0>, ap:<255,255>, sta:<9,0>, prof:1
I (7768) WIFI: SYSTEM_EVENT_STA_DISCONNECTED: 8
It seems you’re TLS handshake is failing. Have you done the prerequisites in order to create certificates and a thing in AWS IoT Core?
Here is where you can find the prequisite guide https://docs.aws.amazon.com/freertos/latest/userguide/freertos-prereqs.html.
I have had a lot of success with the quick start script found here: https://github.com/aws/amazon-freertos/tree/master/tools/aws_config_quick_start. That script will help you get connected to the cloud in one step.
Yes Carl. I created all the certificates and policies required for the tests. I tested the MQTT Demo from a PIC32 Curiosity Board and it works, sending the MQTT Message of the demo. I have checked the messages in the AWS IoT Core.
But the same demo, with the same certificates and policies doesn’t work in the ESP32. This is my problem. Is the same test but it doesn’t work.
I downloaded the previous OS version, 201912.00… and the demo works… je je… I believe that is a bug including in the last version… by the moment I will continue my work with the version 201912 that works
Interesting, well I am glad you were able to connect in the older version. If you should try another stab at this, please enable mbedTLS debugging and set the debug level to 4, and I would be happy to take a look at the mbedTLS logs. Please let me know if you need assistance completing these steps.
Could you remember the file where is located the flags to enable and set the mbedTLS debugging?
Hi Carl. Sorry for the delay… Today I retake the tests with the version 2020.00. I unzipped the code again and I configured the credentials, but this time the code worked… It confuses the results. I remembered that the last week I changed my Wifi router and it can be the reason for the code works this time… Sorry for report this situation, but now the MQTT demo is working… I don’t understand for why reason the previous Wifi router had this problem… Thanks for all your support