Hello Arduino Forum. This is my first Arduino project, but i have been using WINAVR for years. My goal is to create a data logging device with a web interface. I am using an Arduino Ethernet. The issue I am encountering occurs with no hardware attached.
The basic problem is that sometimes when the arduino reads from the SD card it obtains erroneous data. Here is the function where the undesired behaviour is occuring:
In Webserve.cpp:
int sendSdFile(EthernetClient _client, char* fname, byte ftype){
// send rest of HTTP header
HTTPheader(_client, ftype);
// send web page
File wFile;
if(ftype == OCTET){
wFile = SD.open(fname); // open web page file
#ifdef DEBUG
Serial.println(fname);
#endif
}
else{
char fullpath[20];
strcpy_P(fullpath, (const prog_char*)F("WEB/"));
strcat(fullpath, fname);
#ifdef DEBUG
Serial.println((int)wFile);
#endif
wFile = SD.open(fullpath); // open web page file
#ifdef DEBUG
Serial.println(fullpath);
Serial.println((int)wFile);
Serial.println(F("FR:"));
Serial.println(freeMemory(), DEC);
#endif
}
if (wFile) {
unsigned int wdt_stamp = millis();
while(wFile.available()) {
byte b = wFile.read();
_client.write(b); // send web page to client
#ifdef DEBUG
Serial.print(b);
#endif
halfminutewdtreset(wdt_stamp);
}
wFile.close();
#ifdef DEBUG
Serial.println(F("FC"));
#endif
}else _client.println(F("File Send Fail!"));
}
I have DEBUG #defined and I see the following on the serial port:
0
WEB/blank.js
1
FR:
1657
255255255255255255255255255255255255255255255255255255255255255255255255255(and more you get the point)
255FC
Note that this failure mode doesnt normally occur the first time i run the function. I have to reload the web page 1 or 2 times to get this failure to occur. I am totally baffled at these failures, please help if you can. ![]()
I attached a complete set of files.
Thanks in advance.
Compatibility_Sensors.zip (11.9 KB)
WEB.zip (12.7 KB)
Serial Response.txt (1.81 KB)
