-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Was playing with this at the weekend and never got it to work reliably, the cache file written as cache.write(client.read()); is always 0 bytes long.
I started wondering if this was my SD or ethernet board behaving weirdly so adapted a small test script that seems to run fine (see below).
Do you have any other suggestions as to what might be causing the problem? We tried removing the debouncing to reduce the flash memory usage below 30,000 but that didn't seem to help either
This is on an Arduino Uni with the Ethernet Shield and a 1gb/2gb/16gb microsd card (see the same issue with all three cards), have also tried formatting to Fat16 and Fat32 using various rools.
Test program which checks the card is working:
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
const int chipSelect = 4;
int loops = 0;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x85, 0x7F };
void setup()
{
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.print("Setting up network");
if(Ethernet.begin(mac)) {
Serial.println("Got ethernet");
} else {
Serial.println("Ethernet failed");
}
delay(1000);
Serial.print("IP: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
String dataString = "";
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
File dataFile = SD.open("MYLOG.TXT", FILE_WRITE);
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else {
Serial.println("Failed to write to SD card: MYLOG.TXT");
while(true); // stop trying
}
loops++;
if(loops > 3) {
while(true); // stop trying
}
}
Output from test program:
Initializing SD card...card initialized.
Setting up networkGot ethernet
IP: 192.168.2.2
505,399,337
404,393,365
414,419,398
404,411,404
Output from printer program in debug mode:
0: Doing setup - I've added this
0: ID: 7p2x6b2w7n7w3q1e
20: SD card loaded - I've added this
5520: IP: 192.168.2.2
... snip ...
15759: Attempting to connect to printer.exciting.io
15845: Waiting for data
15845: Waiting for data
15846: Waiting for data
15855: Waiting for data
15881: Waiting for data
15907: Waiting for data
15933: Waiting for data
15988: Content length: 9185
17996: Waiting for data
17997: Server disconnected
18016: Failure, content length: 9185
length: 9185
18038: cache: 0