(resolved) issue with HTTP client

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(resolved) issue with HTTP client

Postby mzimmers » Fri Sep 13, 2019 10:26 pm

Hi all -

I've been asked to extend the functionality of our ESP32-based product. We now need to communicate with an Informacast server.

Here's a bit of code:

Code: Select all

                client = esp_http_client_init(&config);
                err = esp_http_client_perform(client);
                ESP_LOGI(TAG, "doInformacastStuff(): esp_http_client_perform() returned %d.", err);
When I execute the perform, I get a system error:

Code: Select all

E (5552) HTTP_CLIENT: Connection failed, sock < 0
I (5552) Worker: doInformacastStuff(): esp_http_client_perform() returned 28674
Other people have attributed the system error to an insufficient number of sockets, but I don't believe that's my problem. Plus I don't understand why I'm getting an error code other than ESP_OK or ESP_FAIL.

I'm sure my configuration struct isn't properly set, but I was going to deal with that later. Right now, I'm just trying to figure out this error message. Can anyone help shed some light on this?

Thanks...
Last edited by mzimmers on Thu Oct 24, 2019 10:54 pm, edited 1 time in total.

boarchuz
Posts: 610
Joined: Tue Aug 21, 2018 5:28 am

Re: issue with HTTP client

Postby boarchuz » Fri Sep 13, 2019 10:42 pm


User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: issue with HTTP client

Postby mzimmers » Sat Sep 14, 2019 1:12 am

I agree, but I don't know why. I'm not even sure from the docs how I'm supposed to use this facility. Do I use it in conjunction with LwIP, or instead of? If the former, do I create a socket, and if so, do I connect to it (I'm guessing not this)?

I wish the error code was a little more informative; "socket < 0" doesn't tell me much.

Thanks...

boarchuz
Posts: 610
Joined: Tue Aug 21, 2018 5:28 am

Re: issue with HTTP client

Postby boarchuz » Sat Sep 14, 2019 11:23 am

You can see in tcp_connect the reasons where it might return -1 (failed). Your log will allow you to identify what the reason is in your case, but there's no way for us to know with just two lines of it available.
If there's no previous relevant output from tcp_connect in your log then you can assume the DNS lookup failed (I agree it probably should explicitly log this).

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: issue with HTTP client

Postby mzimmers » Mon Sep 16, 2019 4:08 pm

Hi boarchuz - thanks for the help with this. It turned out to be (as usual) cockpit error: I was allowing one of my yuarel buffers to be overwritten before the call to esp_http_client_perform(), so it had a malformed host field.

For anyone else who encounters similar problems, the answer to my questions above about using with or without LwIP is "without" -- the ESP32 HTTP client API appears to be entirely self-contained, so there's no need for calls to LwIP socket() or connect().

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 120 guests