This seems so simple, but I'm having a really hard time figuring it out.
Multiple symptoms & questions in a single piece of code.
this exact code worked last night - zero other changes that I'm aware of.
The incoming text file was around 150KB, and I could transfer and open the file in my browser - no problem.
But if I tried to transfer from 'half-way-through' the file it only sent an empty file!
webClient() is open and connected outside this code - and is valid (since the transfer header seems to get through ok...)
Today with smaller files <1KB - nothing at all, yet the SD.read is functioning as expected.
If I check the file read() - the chars are all coming in as expected, and reaching the write() function. Just not getting to the client??! Tell me it's something obvious!
I should add that the browser's download indicator showed progress when the files /were/ transferring, but just appear and wait for me to click them with the empty files...
tl;dr; Worked with an entire large file, but not smaller, or partial files.
Today not at all... ?!!
THE CODE:
//==================================================
void send_file() {
//==================================================
char c, tempBuffer[32];
int rCounter;
File srcFile;
webClient.println("HTTP/1.1 200 OK");
webClient.println("Content-Type: text/plain");
webClient.println("Content-disposition: attachment; filename=theFile.txt");
webClient.println("Connection: close");
srcFile = SD.open("incoming.txt", FILE_READ);
if (srcFile) {
srcFile.seek(0L);
while (srcFile.available()) {
// read file chunks into a buffer
char *rPtr = tempBuffer; // pointer to start of buffer
for (rCounter=0; rCounter < sizeof(tempBuffer); rCounter++) {
c = srcFile.read();
if (c < 0) break; // end of file - fall through to write()
*rPtr++ = c;
}
// send packet of rCounter bytes to webclient
webClient.write(tempBuffer, rCounter);
}
logFile.close();
}
webClient.stop();
}
//==================================================