esp_http_client problem

DannyBackx
Posts: 32
Joined: Wed Sep 19, 2018 7:17 pm

esp_http_client problem

Postby DannyBackx » Sat Oct 13, 2018 6:29 am

Hey,
Are there known problems with esp_http_client code ?
I use the code below to download gif images, and get intermittent failures.
It looks like the download is wrong, see dump lower.
Thanks for any help.
Danny

Code: Select all

char *LoadGif::loadGif(const char *url, size_t *data_size) {
  esp_http_client_handle_t http_client;
  esp_http_client_config_t http_config;

  memset(&http_config, 0, sizeof(http_config));

  http_config.url = url;

  ESP_LOGD(loadgif_tag, "LoadGif(%s)", url);

  http_client = esp_http_client_init(&http_config);
  esp_err_t err = esp_http_client_open(http_client, 0);

  if (err != ESP_OK) {  // Not connected
    ESP_LOGE(loadgif_tag, "Could not connect to %s", url);
    http_config.url = 0;
    esp_http_client_close(http_client);
    esp_http_client_cleanup(http_client);
    return 0;
  }

  int content_length = esp_http_client_fetch_headers(http_client);
  if (content_length < 0) {
    ESP_LOGE(loadgif_tag, "Content length not found %d\n", content_length);
    http_config.url = 0;
    esp_http_client_close(http_client);
    esp_http_client_cleanup(http_client);
    return 0;
  }
  ESP_LOGI(loadgif_tag, "Content length %d", content_length);

  if (buf)
    free((void *)buf);

  buflen = content_length + 4;          // a bit of buffer after...
  buf = (char *)malloc(buflen);

  int pos = 0, total = 0, rlen = 0;
  while (total < content_length && err == ESP_OK) {
    rlen = esp_http_client_read(http_client, buf + pos, content_length - total);
    if (rlen < 0) {
      ESP_LOGE(loadgif_tag, "error reading data");
      esp_http_client_close(http_client);
      esp_http_client_cleanup(http_client);
      free(buf); buf = 0;
      http_config.url = 0;
      return 0;
    }

    pos += rlen;
    total += rlen;
    ESP_LOGI(loadgif_tag, "rlen = %d, pos %d, total %d", rlen, pos, total);
  }

  ESP_LOGI(loadgif_tag, "reply ok, downloaded %d bytes", total);

  esp_http_client_close(http_client);
  esp_http_client_cleanup(http_client);

  http_config.url = 0;

  if (data_size)
    *data_size = total;

  return buf;
}
Logging, see zeroes and junk after offset 070 :

Code: Select all

Querying api.wunderground.com .. ok
I (10155) Weather: Content length 2570
I (10165) LoadGif: LoadGif(http://icons.wxug.com/i/c/k/nt_clear.gif)
I (10245) LoadGif: Content length 1647
I (10245) LoadGif: rlen = 1647, pos 1647, total 1647
I (10255) LoadGif: reply ok, downloaded 1647 bytes
I (10255) LoadGif: Download -> len 1647
I (10255) LoadGif: Download 000 : 47 49 46 38 39 61 32 00 32 00 d5 20 00 96 d2 eb GIF89a2.2.. ....
I (10265) LoadGif: Download 010 : 6d c1 e1 8d d0 e3 81 c9 e7 a9 dd e5 62 bc e1 5c m...........b..\
I (10275) LoadGif: Download 020 : ba df 62 bc e0 83 cb e2 77 c5 e5 ab db ef f4 fa ..b.....w.......
I (10285) LoadGif: Download 030 : fd ea f6 fb d5 ed f7 c0 e4 f3 8c ce e9 98 d5 e4 ................
I (10295) LoadGif: Download 040 : 78 c6 e1 b5 df f1 67 bf e0 df f1 f9 7d c9 e2 72 x.....g.....}..r
I (10305) LoadGif: Download 050 : c4 e1 93 d3 e3 88 ce e2 6c c0 e3 9e d8 e4 ca e8 ........l.......
I (10315) LoadGif: Download 060 : f5 a3 da e4 a1 d7 ed 57 b7 df ae df e5 ff ff ff .......W........
I (10325) LoadGif: Download 070 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I (10335) LoadGif: Download 080 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I (10345) LoadGif: Download 090 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I (10355) LoadGif: Download 0a0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I (10365) LoadGif: Download 0b0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
I (10375) LoadGif: Download 0c0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 21 ff 0b .............!..
I (10385) LoadGif: Download 0d0 : 58 4d 50 20 44 61 74 61 58 4d 50 3c 3f 78 70 61 XMP DataXMP<?xpa
I (10395) LoadGif: Download 0e0 : 63 6b 65 74 20 62 65 67 69 6e 3d 22 ef bb bf 22 cket begin="..."



chegewara
Posts: 2237
Joined: Wed Jun 14, 2017 9:00 pm

Re: esp_http_client problem

Postby chegewara » Sat Oct 13, 2018 10:15 am

Im guessing you see exactly what is being sent:
https://en.wikipedia.org/wiki/Extensibl ... a_Platform
This is an example XML document for serialized XMP metadata in a JPEG photo:

<?xpacket begin="?" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.4-c002 1.000000, 0000/00/00-00:00:00 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
Also searching for DataXMP i foud this:
https://wiki.whatwg.org/wiki/GIF

and then this:
http://wwwimages.adobe.com/www.adobe.co ... nPart3.pdf

DannyBackx
Posts: 32
Joined: Wed Sep 19, 2018 7:17 pm

Re: esp_http_client problem

Postby DannyBackx » Sat Oct 13, 2018 12:45 pm

Thanks, I guess I need to look at the gif decoding then.

Who is online

Users browsing this forum: Google [Bot], ok-home and 143 guests