Page 1 of 1

(resolved) issue with HTTP client

Posted: Fri Sep 13, 2019 10:26 pm
by mzimmers
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...

Re: issue with HTTP client

Posted: Fri Sep 13, 2019 10:42 pm
by boarchuz

Re: issue with HTTP client

Posted: Sat Sep 14, 2019 1:12 am
by mzimmers
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...

Re: issue with HTTP client

Posted: Sat Sep 14, 2019 11:23 am
by boarchuz
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).

Re: issue with HTTP client

Posted: Mon Sep 16, 2019 4:08 pm
by mzimmers
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().