Sketch stops responding if download fails or is canceled forcing reset of the CC3000 Shield. At this point connections fail until CC3000 is re-initialized.
if (StrContains(HTTP_req, "GET /log.txt")) {
webFile = SD.open("log.txt");
if (webFile) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/octet-stream");
client.println("Content-Disposition: attachment");
//client.println("Content-Length: ");
client.println(webFile.available());
client.println("Connnection: close");
client.println();
//this goes in the function that sends the data
char buffer[ BUFSIZE ];
int i;
while ( webFile.available() ) {
for (i=0 ; (i < BUFSIZE) && (buffer[ i-1 ] >= 0) ; i++) {
buffer[i] = webFile.read();
}
client.write( buffer, (buffer[i-1] >= 0) ? i : i-1 );
}
}
webFile.close();
delay(15);
}
Any suggestions? Download does complete some of the time; just not every time. When it fails; that is the problem.
Complete sketch attached; requires Arduino Mega 2560 due to memory requirements.