-->
Page 1 of 1

Helps to increase the speed of transfer

PostPosted: Wed Jul 29, 2015 7:50 am
by Artur Gaspar
I am building an interface using JQuery , I could make everything work perfectly, but I have a speed problem.
When you send an image or a file that is not HTML I am using the routine below.
Works but believe she is to blame for the low speed.
Any ideas on how to improve ?

Code: Select all  String arq;

  if (dataType == "text/html") {
    while (dataFile.available()) {
      arq += char(dataFile.read());
    }
    server.send(200, dataType, arq);
  } else {
    char a[500];
    WiFiClient client = server.client();
    while (dataFile.available()) {
      for (int i = 0; i < 500; i++) {
        a[i] = dataFile.read();
      }
      client.write(&a[0], 500);
    }
  }

Re: Helps to increase the speed of transfer

PostPosted: Thu Jul 30, 2015 11:34 pm
by SwiCago
There is a method called "streamFile"
just like server.sendContent or sendHeader

Usage is: template<typename T> size_t streamFile(T &file, String contentType)
Exxample usage:
Code: Select allif(server.streamFile(dataFile,"image/jpeg") != dataFile.size()) {
  Serial.printLn("Did not stream entire file, maybe file path not correct!");
}


Here is a full sample(not mine) in git on how it is used. You'll be able to pull the bits you need and get it to work (Read/Write files to SD card via webserver)
https://github.com/esp8266/Arduino/blob ... Server.ino