lpcware

Problem with lwip/webserver_freertos

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by alramlechner on Mon Aug 10 05:59:18 MST 2015
hi,

i am using the LPC1768 webserver_freertos LPCOpen example. i am running into strange problems with an PC application connected via TCP to the MCU. because i spent hours of debugging and can't really find the problem, i tried to reproduce some similiar behavior with the original code. and that was quite easy.

i just brought the webserver_freertos example (vanilla code) running and just modified the netconn_fs.c in the following way:

old code:
line 47:
const static char http_index_html[] = "<html><head><title>Congrats!</title></head><body><h1>Welcome to our lwIP HTTP server!</h1>

This is a small test page, served by httpserver-netconn.</body></html>";


near line 135:
      netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_html, sizeof(http_index_html)-1, NETCONN_NOCOPY);


modified to call netconn_write more often:


const static char http_index_start_html[] = "<html><head><title>Congrats!</title></head><body><h1>Welcome to our lwIP HTTP server!</h1>

This is a small test page, served by httpserver-netconn.<table>";
const static char http_index_data_html[] = "<tr><td>cell1</td><td>cell2</td><td>cell3</td><td>cell4</td><td>cell5</td></tr>";
const static char http_index_end_html[] = "</table></body></html>";




      netconn_write(conn, http_index_start_html, sizeof(http_index_start_html)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_data_html, sizeof(http_index_data_html)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_end_html, sizeof(http_index_end_html)-1, NETCONN_NOCOPY);


i think that should be a harmless change - but the webserver isn't responding any longer. i captured the whole traffic with wireshark. there are problems with TCP fragement overlaps. (wireshark capture attached)

the interesting part: it is working, as soon as i call netconn_write really often:


      netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_start_html, sizeof(http_index_start_html)-1, NETCONN_NOCOPY);
      uint32_t i;
      for(i=0; i<100; i++)
      netconn_write(conn, http_index_data_html, sizeof(http_index_data_html)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_end_html, sizeof(http_index_end_html)-1, NETCONN_NOCOPY);


another workaround is, to enabled TCP_NO_DELAY:


      conn->pcb.tcp->flags |= TF_NODELAY;
      netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_start_html, sizeof(http_index_start_html)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_data_html, sizeof(http_index_data_html)-1, NETCONN_NOCOPY);
      netconn_write(conn, http_index_end_html, sizeof(http_index_end_html)-1, NETCONN_NOCOPY);


is there anything, i made wrong? i think, that should work ...

additionally i found some possible other problems in that example code:
configASSERT is not defined. defining it will produce some assertion errors. for example: the eth rx/tx tasks are started with priorities 5 and 6. but FreeRTOS config only allows 5 priorities. so the tasks will be running at the same priority (which is 4). the tcp ip thread is running with priority 3. but lwipopts.h says, tcp ip thread should run at higher priority than MAC threads ... chaning that, wont' change any to above errors.

are there any suggestion, what should help?

thanks!

Outcomes