I have a data file that reads correctly in the latest SdFat library Google Code Archive - Long-term storage for Google Code Project Hosting., readlog example; however, with current code zoomkat's buffered file read only reads the first 44 lines and a partial line.
How can this readlog be converted to output to server instead of serial output? I tried changing ArduinoOutStream cout(Serial); to ArduinoOutStream(server); which produced an error.
.
/*
* Read the logfile created by the eventlog.pde example.
* Demo of pathnames and working directories
*/
#include <SdFat.h>
// SD chip select pin
const uint8_t chipSelect = SS;
// file system object
SdFat sd;
// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
void setup() {
int c;
Serial.begin(9600);
while (!Serial) {} // wait for Leonardo
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
// set current working directory
if (!sd.chdir("LOGS/2011/JAN/")) {
sd.errorHalt("chdir failed. Did you run eventlog.pde?");
}
// open file in current working directory
ifstream file("LOGFILE.TXT");
if (!file.is_open()) sd.errorHalt("open failed");
// copy the file to Serial
while ((c = file.get()) >= 0) cout << (char)c;
cout << "Done" << endl;
}
//------------------------------------------------------------------------------
void loop() {}
Current code using zoomkat's packet file reading code::
if (StrContains(HTTP_req, "GET /log.txt")) {
webFile = SD.open("log.txt");
if (webFile) {
server.println("HTTP/1.1 200 OK");
server.println("Content-Type: application/octet-stream");
server.println("Content-Disposition: attachment");
server.println("Content-Length: ");
server.println(webFile.available());
server.println();
byte clientBuf[64];
int clientCount = 0;
while(webFile.available())
{
delay(1);
clientBuf[clientCount] = webFile.read();
clientCount++;
if(clientCount > 63)
{
// Serial.println("Packet");
server.write(clientBuf,64);
clientCount = 0;
}
}
}
// close the file:
webFile.close();
}