SD and client.write
Posted: Sat Feb 18, 2017 7:00 pm
Hi,
I'm loading HTML pages to the client from an SD card. It works with client.write(myFile.read()); fine but there is a lag in performance so I implemented loading the file by chunks rather than one byte at a time. I've done with on an Arduino fine but it won't compile for the ESP8266. I can't figure out the problem.
Here's the error
I'm loading HTML pages to the client from an SD card. It works with client.write(myFile.read()); fine but there is a lag in performance so I implemented loading the file by chunks rather than one byte at a time. I've done with on an Arduino fine but it won't compile for the ESP8266. I can't figure out the problem.
Code: Select all
byte tBuf[64];
unsigned int lastPosition = 0;
File myFile = SD.open(page); // open web page file
if (myFile) {
// send a standard http response header
client.println(F("HTTP/1.1 200 OK"));
if(webParser.contains(page, ".jpg")){
client.println(F("Content-Type: image/jpeg"));
client.println(F("Cache-Control: max-age=36000, public"));
} else if(webParser.contains(page, ".gif")){
client.println(F("Content-Type: image/gif"));
client.println(F("Cache-Control: max-age=36000, public"));
} else if(webParser.contains(page, ".png")){
client.println(F("Content-Type: image/png"));
client.println(F("Cache-Control: max-age=36000, public"));
} else if(webParser.contains(page, ".htm")){
client.println(F("Content-Type: text/html"));
} else if(webParser.contains(page, ".js")){
client.println(F("Content-Type: application/javascript"));
} else if(webParser.contains(page, ".css")){
client.println(F("Content-Type: text/css"));
}
client.println();
while(myFile.available())
{
myFile.read(tBuf,64);
client.write(tBuf, myFile.position() - lastPosition);
lastPosition = myFile.position();
//yield for esp8266 processes
yield();
//multiple bytes doesn't work for esp8266
//client.write(myFile.read());
}
myFile.close();
// disconnect the SD card
Here's the error
Code: Select all
n file included from /Users/minh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/ESP8266WiFi.h:39:0,
from /Users/minh/Documents/Arduino_esp8266/ESP8266_WAAC_WebServer/ESP8266_WAAC_WebServer.ino:6:
/Users/minh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClient.h: In instantiation of 'size_t WiFiClient::write(T&, size_t) [with T = unsigned char [64]; size_t = unsigned int]':
/Users/minh/Documents/Arduino_esp8266/ESP8266_WAAC_WebServer/ESP8266_WAAC_WebServer.ino:201:67: required from here
/Users/minh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClient.h:123:36: error: request for member 'available' in 'source', which is of non-class type 'unsigned char [64]'
size_t left = source.available();
^
/Users/minh/Library/Arduino15/packages/esp8266/hardware/esp8266/2.3.0/libraries/ESP8266WiFi/src/WiFiClient.h:127:5: error: request for member 'read' in 'source', which is of non-class type 'unsigned char [64]'
source.read(buffer.get(), will_send);
^