MQTTRecvFailed in FreeRTOS Reference Integration

Hi, I have been trying to set up the FreeRTOS AWS reference integration over the past few days. Currently, I have come across an issue where I get MQTTRecvFailed constantly, with nothing sent to AWS IoT Core. The output of the terminal is below:

I (1125) wifi:set rx beacon pti, rx_bcn_pti: 14, bcn_timeout: 14, mt_pti: 25000, mt_time: 10000
I (1155) wifi:idx:0 (ifx:0, 04:42:1a:9e:31:01), tid:6, ssn:1, winSize:64
I (1305) wifi:AP’s beacon interval = 102400 us, DTIM period = 1
I (1315) wifi:sta rx csa, newchan=2, old=2
I (1615) wifi:sta rx csa, newchan=2, old=2
I (1625) wifi:idx:1 (ifx:0, 04:42:1a:9e:31:01), tid:0, ssn:1, winSize:64
I (1875) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (2125) wifi:sta rx csa, newchan=2, old=2
I (2135) core_mqtt_agent_manager: WiFi connected.
I (2135) app_wifi: Connected with IP Address:192.168.50.13
I (2135) esp_netif_handlers: sta ip: 192.168.50.13, mask: 255.255.255.0, gw: 192.168.50.1
I (2875) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (3155) wifi:sta rx csa, newchan=2, old=2
I (3665) wifi:sta rx csa, newchan=2, old=2
I (3875) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (4175) wifi:sta rx csa, newchan=2, old=2
I (4925) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (5615) wifi:sta rx csa, newchan=2, old=2
I (5665) core_mqtt_agent_manager: Session present: 0

E (5665) core_mqtt_agent_manager: MQTT_Status: MQTTRecvFailed
I (5925) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (5975) core_mqtt_agent_manager: Retry attempt 1.
I (6225) wifi:sta rx csa, newchan=2, old=2
I (7045) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (7145) wifi:sta rx csa, newchan=2, old=2
I (7245) wifi:sta rx csa, newchan=2, old=2
I (7275) core_mqtt_agent_manager: Session present: 0

E (7275) core_mqtt_agent_manager: MQTT_Status: MQTTRecvFailed
I (7725) core_mqtt_agent_manager: Retry attempt 2.
I (8375) wifi:sta rx csa, newchan=2, old=2
I (8745) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (9295) wifi:sta rx csa, newchan=2, old=2
I (9505) wifi:sta rx csa, newchan=2, old=2
I (9605) wifi:sta rx csa, newchan=2, old=2
I (9745) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (9915) wifi:sta rx csa, newchan=2, old=2
I (10215) wifi:sta rx csa, newchan=2, old=2
I (10325) wifi:sta rx csa, newchan=2, old=2
I (10585) core_mqtt_agent_manager: Session present: 0

E (10585) core_mqtt_agent_manager: MQTT_Status: MQTTNoDataAvailable
I (10745) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (11245) wifi:sta rx csa, newchan=2, old=2
I (11745) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (12055) core_mqtt_agent_manager: Retry attempt 3.
I (12165) wifi:sta rx csa, newchan=2, old=2
I (12475) wifi:sta rx csa, newchan=2, old=2
I (12775) wifi:sta rx csa, newchan=2, old=2
I (13185) wifi:sta rx csa, newchan=2, old=2
I (13495) ota_over_mqtt_demo: Received: 0 Queued: 0 Processed: 0 Dropped: 0
I (13715) core_mqtt_agent_manager: Session present: 0

To try and debug the issue, I have reinstalled the idf on both terminal and VSCode, as well as tried to run each demo individually, to see if I could get any to work, which didn’t give a result.

I am not sure if there is something I am missing, but I have tried to copy the instructions on Git closely, including recloning the repository multiple times, but to no avail. Any help would be appreciated, thanks!

Hi @Azareal2120,
Assume that you’re using ESP32C3. I can’t find this log coreMQTT: MQTT connection established with the broker. on your output. Which means you’re not able to connect MQTT broker. Could you help to enable coreMQTT log by following steps and provide the output again?

  1. idf.py menuconfig
  2. Component config
  3. coreMQTT
  4. Logging
  5. Enable all

Thanks.

Hi @ActoryOu and @Azareal2120

I’m targeting esp32s3 for the tempSubPubLED demo, enabled coreMQTT logging and seeing the following in the logs. The retry loops and appears to never connect. Any recommendations?

I (4603) core_mqtt_agent_manager: WiFi connected.
I (4603) app_wifi: Connected with IP Address:10.1.10.221
I (4603) esp_netif_handlers: sta ip: 10.1.10.221, mask: 255.255.255.0, gw: 10.1.10.1
I (4613) wifi:<ba-add>idx:1 (ifx:0, 5c:7d:7d:9b:a3:e7), tid:0, ssn:0, winSize:64
I (6003) core_mqtt_agent_manager: Retry attempt 1.
I (7453) core_mqtt_agent_manager: Retry attempt 2.
I (9973) core_mqtt_agent_manager: Retry attempt 3.

Have you done these steps?

You are seeing log form this line which means this loop is not able to connect to AWS IoT. Can you add following logs to this loop to find out where we are failing-

        do
        {
            xTlsRet = xTlsConnect( pxNetworkContext );

            if( xTlsRet == TLS_TRANSPORT_SUCCESS )
            {
                if( esp_tls_get_conn_sockfd( pxNetworkContext->pxTls, &lSockFd ) == ESP_OK )
                {
                    eMqttRet = prvCoreMqttAgentConnect( xCleanSession );
                }
                else
                {
                    ESP_LOGE( TAG, "esp_tls_get_conn_sockfd failed." );
                    eMqttRet = MQTTBadParameter;
                }

                if( eMqttRet != MQTTSuccess )
                {
                    ESP_LOGE( TAG,
                              "MQTT_Status: %s",
                              MQTT_Status_strerror( eMqttRet ) );
                }
            }
            else
            {
                ESP_LOGE( TAG, "xTlsConnect failed." );
            }

            if( eMqttRet != MQTTSuccess )
            {
                xTlsDisconnect( pxNetworkContext );
                xBackoffRet = prvBackoffForRetry( &xReconnectParams );
            }


        } while( ( eMqttRet != MQTTSuccess ) && ( xBackoffRet == pdPASS ) );

Also, enable logs for esp_tls.

Hi @aggarg … thank you for getting back so quickly.
It’s working now.

The only difference to report was when it wasn’t working, I was on a different wifi network.
Logs showed I was getting an IP, but maybe it couldn’t reach the internet. not sure.

thanks again!

Glad that it works for you!