lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] http client callback functions


From: koszo.simon
Subject: [lwip-users] http client callback functions
Date: Fri, 5 Jul 2019 05:52:02 -0700 (MST)

As you could notice from my previous posts lately (I hope these posts did not
bother anybody too much): I am trying to get familiar with the built in http
client in lwIP 2.1.2.

I could finally download a simple bmp file from the server with using the
built in http client. Now I would like to implement somehow a workaround, if
the requested .bmp file cannot be found on the server so the server gives
back "404 Not Found" answer. 

Hence I wanted to start to use httpc_headers_done_fn callback and
httpc_result_fn callback functions. Here you can see my code (dprintf()
function prints debug messages to a serial port):




char url[500];
char domain_name[30];
httpc_connection_t *conn_settings;
httpc_state_t *connection;

conn_settings->use_proxy = 0;   //nincs proxy használat
conn_settings->headers_done_fn = RecvHttpHeaderCallback;
conn_settings->result_fn = HttpClientResultCallback;

strcpy(domain_name, "www.procontrol.hu");
strcpy(url, "/sendfile/Proxer60_SD_card/");
strcat(url, filename_loc);
dprintf("url:\n%s\n", url);
err_t error;
error = httpc_get_file_dns(domain_name, 80, url, conn_settings,
RecvBMPDrawCallback, NULL, &connection);   //HTTP üzenet elküldése
dprintf("error: %u\n", error);



err_t RecvHttpHeaderCallback (httpc_state_t *connection, void *arg, struct
pbuf *hdr, u16_t hdr_len, u32_t content_len) {
   dprintf("RecvHttpHeaderCallback has been called at: %lu\n",
GetUpTimeMs());
   return ERR_OK;
}


void HttpClientResultCallback (void *arg, httpc_result_t httpc_result, u32_t
rx_content_len, u32_t srv_res, err_t err) {
   dprintf("HttpClientResultCallback has been called at: %lu\n",
GetUpTimeMs());
   dprintf("httpc_result: %u\n", httpc_result);
   dprintf("received number of bytes: %lu\n", rx_content_len);
}


err_t RecvBMPDrawCallback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
err_t err) {
    if (p == NULL) {
      dprintf("pbuf==NULL TCP packet has arrived at: %lu\n", GetUpTimeMs());
    } else {
       if (!BMPPacketCnt) {   //első csomag feldolgozása
          dprintf("First packet recieved at: %lu\n", GetUpTimeMs());

          memcpy(&BMPHeader, p->payload, sizeof(BMPHeader));
          BMPHeader.height = abs(BMPHeader.height);
          dprintf("BMPHeader.filesize: %lu\n", BMPHeader.filesize);
        }

        BMPIncomingBytes = BMPIncomingBytes + p->len;
        BMPPacketCnt++;

        tcp_recved(tpcb, p->tot_len);
        pbuf_free(p);

        if (BMPIncomingBytes >= BMPHeader.filesize) {
           dprintf("incoming bytes (%lu) >= filesize (%lu)\n",
BMPIncomingBytes, BMPHeader.filesize);
           dprintf("Last packed recieved -> closing of the tcp connection
has been initiated at: %lu\n", GetUpTimeMs());
           BMPIncomingBytes = 0;
           BMPPacketCnt = 0;
           return tcp_close(tpcb);
        }
    }
    return ERR_OK;
}



I got the following debug messages on the serial port:

14:44:33.787> url:
14:44:33.787> /sendfile/Proxer60_SD_card/pictures/289958356.bmp
14:44:33.787> error: 0
14:44:33.787> First packet recieved at: 1666506
14:44:33.858> BMPHeader.filesize: 226872
14:44:33.973> incoming bytes (226872) >= filesize (226872)
14:44:33.973> Last packed recieved -> closing of the tcp connection has been
initiated at: 1666640

I miss the debug messages of RecvHttpHeaderCallback() function and
RecvHttpHeaderCallback() function.

Do you think that I am configure something badly? Does anybody have any idea
what can be the reason that these functions have not been called? 

Thank you in advance for any help:
Simon






--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]