mbedtls_net_connect returned -0x42 , need more info

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

mbedtls_net_connect returned -0x42 , need more info

Postby preetam » Thu Jun 29, 2017 3:46 pm

Hi All,

I have several tasks running on esp32, in which two of them are socket server and mqtt connection to aws (same as https://github.com/espressif/esp-idf/bl ... h_sample.c)

I have enabled SO_REUSEADDR, SO_REUSEPORT and Max number of open sockets to 16(max as per the help info) in menu config.
I was testing a scenario as follows:

1. Successfully flashed without any error to esp32 with highest priority for mqtt tasks and others at same priority lower than mqtt task.
2. Successfully connected to aws iot. Able to publish and subscribe.
-- autoreconnect set to true with available disconnectCallbackHandler.

3. Remove LAN wire from WiFi router, wait for 5 minutes.

4. Now once i plug back the LAN Wire , the mqtt task tries to reconnect using disconnectCallbackHandler but fails with "mbedtls_net_connect returned" -0x42 (-0x0042 /**< Failed to open a socket. */ from mbedtls/net.h), did try to increase the stack of the task , but on the second attempt fails

I Assume that by the time the mqtt task tries to reconnect all the sockets are in use and hence this fails , Is there a way to bind a port to mbedtls permanently for mqtt connection and aslo is there any way to use LINGER settings on the sockets?

Any suggestion will be very helpful

Thank you
Paul

f.h-f.s.
Posts: 214
Joined: Thu Dec 08, 2016 2:53 pm

Re: mbedtls_net_connect returned -0x42 , need more info

Postby f.h-f.s. » Fri Jun 30, 2017 1:37 pm

You can enable socket debug in lwip https://github.com/espressif/esp-idf/bl ... pts.h#L628

This will print some more information about the sockets set up and the errors

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: mbedtls_net_connect returned -0x42 , need more info

Postby preetam » Fri Jun 30, 2017 2:15 pm

Hi,

Thank you for the suggestion.

I tried to reduce the number of Max number of open sockets to 12 and disabled SO_REUSEPORT, now i am not getting "mbedtls_net_connect returned -0x42 " error but instead getting

E (227303) aws_iot: failed! mbedtls_ssl_handshake returned -0x2700
E (227303) aws_iot: Unable to verify the server's certificate.

I am not sure why this is happening as the initial connection was successful and was able to publish and subscribe.

In addition to above i tried to run the subcribepublish example from https://github.com/espressif/esp-idf/bl ... h_sample.c standalone as only one task, i did not face any issue on this if i disconnect the LAN wire from WiFi Router and plug it back.

On both instances AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL is set to more than 10 mins (in milliseconds)

I will try to investigate this further,

If anybody has any further suggestion please let me know.

Thank you
Paul

f.h-f.s.
Posts: 214
Joined: Thu Dec 08, 2016 2:53 pm

Re: mbedtls_net_connect returned -0x42 , need more info

Postby f.h-f.s. » Fri Jun 30, 2017 2:27 pm

have your certificate settings been freed?

Code: Select all

#define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED               -0x2700  /**< Certificate verification failed, e.g. CRL, CA or signature check failed. */

preetam
Posts: 49
Joined: Thu Jan 26, 2017 2:31 pm
Location: Germany

Re: mbedtls_net_connect returned -0x42 , need more info

Postby preetam » Sat Jul 01, 2017 11:12 pm

Hi,

I am now able to connect to aws. I have to disable accelerations under Component config → mbedTLS in menuconfig and now able to test the above scenario.

Thank you
Paul

chetoxy
Posts: 3
Joined: Sat Apr 08, 2023 6:48 am

Re: mbedtls_net_connect returned -0x42 , need more info

Postby chetoxy » Sat Apr 08, 2023 6:50 am

what is accleration setting ? Can you please explain the steps? I am not able to find it

Who is online

Users browsing this forum: Google [Bot] and 93 guests