-->
Page 1 of 4

Webserver slow to send files

PostPosted: Thu Apr 07, 2016 12:57 pm
by RichardS
Code below has a webserver at wserver, and its requested a file which I send to it, but slowly, approx 500 bytes per second. How can this be made to go faster?

Code: Select allvoid send() {
  int i;

  WiFiClient client = wserver.client();
  makeHeader();
  client.write((uint8_t*)buffer, 50);
  for (i = 0; i < 100; ++i) {
    client.write((uint8_t*)buffer, 1024);
  }
}

Re: Webserver slow to send files

PostPosted: Thu Apr 07, 2016 1:14 pm
by martinayotte
Hi Richard,
Which version of framework are you using ?
Because some of my sketches use to send files from SPIFFS to a browser and files with size around 100K only take about 2-3 seconds.

Re: Webserver slow to send files

PostPosted: Thu Apr 07, 2016 1:25 pm
by RichardS
Not sure Arduino 1.6.4 with board package 2.1.0.

RichardS

Re: Webserver slow to send files

PostPosted: Thu Apr 07, 2016 1:32 pm
by martinayotte
Strange ! Because the packet maximum size is define as HTTP_DOWNLOAD_UNIT_SIZE at 1460.
No other clue to provide other than showing my piece of code :

Code: Select all  if (!SPIFFS.begin()) {
    Serial.println("SPIFFS failed to mount !\r\n");
  }
  File f = SPIFFS.open(filename.c_str(), "r");
  if (!f) {
    String str = "Can't open '" + filename + "' !\r\n";
    Serial.println(str);
  }
  else {
    char buf[1024];
    int siz = f.size();
    webserver.setContentLength(str.length() + siz);
    webserver.send(200, "text/plain", str);
    while(siz > 0) {
      size_t len = std::min((int)(sizeof(buf) - 1), siz);
      f.read((uint8_t *)buf, len);
      buf[len] = 0;
      webserver.client().write((const char*)buf, len);
      siz -= len;
    }
    f.close();
  }