Intermittent HTTP client request failures

milkolik
Posts: 11
Joined: Thu Mar 03, 2022 10:48 pm

Intermittent HTTP client request failures

Postby milkolik » Wed Jun 08, 2022 7:12 pm

Hi, I have an ESP32 connected to a W5500 ethernet IC.

I have a program that starts by doing some GETs and then starts a infinite routine that does POSTs of a small Base64-encoded image once a minute.

The problem is that about 50% of the times I get

Code: Select all

E (153964) TRANSPORT_BASE: tcp_write error, errno=Connection reset by peer
E (153964) HTTP POST request failed: ESP_FAIL
However on the remote server also says that the connection was reset by peer!

I tried this both on a remote server that I have control of and also on Mocklab (service to test requests). I see the same problem on both cases. Also different networks. So the ESP32 must be the problem.

I made a function for requests that 1) creates client config, 2) inits with "esp_http_client_init", 3) does "esp_http_client_perform", 4) gets response/result and 5) runs "esp_http_client_cleanup". Is this correct?

Project built using docker image "release-v4.4".

Anyone getting the same error?

Thank you!
Last edited by milkolik on Wed Jun 08, 2022 7:43 pm, edited 1 time in total.

milkolik
Posts: 11
Joined: Thu Mar 03, 2022 10:48 pm

Re: Intermittent HTTP client request failures

Postby milkolik » Wed Jun 08, 2022 7:33 pm

Logging on debug mode (verbose is crashing on me):

Code: Select all

D (152730) HTTP_CLIENT: set post file length = 102482
D (152730) HTTP_CLIENT: Begin connect to: http://XXXXX.mocklab.io:80
D (152732) esp-tls: host:XXXXX.mocklab.io: strlen 24
D (152738) esp-tls: [sock=54] Resolved IPv4 address: 54.243.4.96
D (152744) esp-tls: [sock=54] Connecting to server. HOST: XXXXX.mocklab.io, Port: 80
D (152892) program: HTTP_EVENT_ON_CONNECTED
D (152893) HTTP_CLIENT: Write header[4]: POST /v1/XXXXX HTTP/1.1
User-Agent: ESP32 HTTP Client/1.0
Host: XXXXX.mocklab.io
Content-Type: application/json
Content-Length: 102482


D (152905) program: HTTP_EVENT_HEADER_SENT
E (155214) TRANSPORT_BASE: tcp_write error, errno=Connection reset by peer
D (155214) program: HTTP_EVENT_ERROR
E (155214) program: HTTP POST request failed: ESP_FAIL
I (155220) program: HTTP_EVENT_DISCONNECTED

a2800276
Posts: 78
Joined: Sat Jan 23, 2016 1:59 pm

Re: Intermittent HTTP client request failures

Postby a2800276 » Wed Jun 08, 2022 8:14 pm

If it's Ethernet it should be fairly simple to sniff and see where the FIN is from. Stab in the dark: there's an IP address conflict in your subnet and a third device sharing the IP of either client or server is closing the connection...

milkolik
Posts: 11
Joined: Thu Mar 03, 2022 10:48 pm

Re: Intermittent HTTP client request failures

Postby milkolik » Thu Jun 09, 2022 12:37 am

Thank you a2800276.

It turned out to be a hardware problem. I built the board using a CMOS oscillator for the W5500 chip thinking that it would work even if the W5500 expected TTL. I though that would work if output was CMOS and TTL input (not the other way round tho). Seems I was wrong. Funny that it worked intermittently.

Switched to some big ass oscillator with TTL output and now it works perfectly every time!

Who is online

Users browsing this forum: Baidu [Spider] and 112 guests