Skip to content

Commit 8735ca4

Browse files
ficetoficeto
ficeto
authored and
ficeto
committed
fixes for sd server example
1 parent 5aa479f commit 8735ca4

File tree

1 file changed

+11
-3
lines changed
  • hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer

1 file changed

+11
-3
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

+11-3
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ bool loadFromSdCard(String path){
8787
uint8_t obuf[WWW_BUF_SIZE];
8888
while (dataFile.available() > WWW_BUF_SIZE){
8989
dataFile.read(obuf, WWW_BUF_SIZE);
90-
client.write(obuf, WWW_BUF_SIZE);
90+
if(client.write(obuf, WWW_BUF_SIZE) != WWW_BUF_SIZE){
91+
Serial.println("Sent less data than expected!");
92+
dataFile.close();
93+
return true;
94+
}
9195
}
9296
//stream the last data left (size is at most WWW_BUF_SIZE bytes)
9397
uint16_t leftLen = dataFile.available();
9498
dataFile.read(obuf, leftLen);
95-
client.write(obuf, leftLen);
99+
if(client.write(obuf, leftLen) != leftLen){
100+
Serial.println("Sent less data than expected!");
101+
dataFile.close();
102+
return true;
103+
}
96104

97105
dataFile.close();
98106
return true;
@@ -124,7 +132,7 @@ void setup(void){
124132
while (WiFi.status() != WL_CONNECTED && i++ < 20) delay(500);
125133

126134
//check if we have connected?
127-
if(i == 20){
135+
if(i == 21){
128136
Serial.print("Could not connect to");
129137
Serial.println(ssid);
130138
//stop execution and wait forever

0 commit comments

Comments
 (0)