Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure, content length: 9185, cache: 0 #47

Open
Pezmc opened this issue Oct 28, 2014 · 6 comments
Open

Failure, content length: 9185, cache: 0 #47

Pezmc opened this issue Oct 28, 2014 · 6 comments

Comments

@Pezmc
Copy link

Pezmc commented Oct 28, 2014

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
@lazyatom
Copy link
Contributor

Hi,

Well done investigating this thus far. Unfortunately I think your test script is maybe a little too simple; you're writing to the file on the SD card, but you're never actually verifying that it was written. To really check that the card was working, I think you need to write quite a bit more data to it, and then check the size of the written file (the original sketch does this by seeking to 0 and then using the size() method), and even potentially start reading from it and printing the data that way, rather than just printing it as it gets written.

Another factor that would be useful is knowing which version of the Arduino IDE you're using; I have a hunch that some of the issues we've seen in the past might relate to specific versions. For what it's worth, when I was developing I tended to use 1.0.5 and seemed to have a lot of success with that - might be worth trying with that version?

@Pezmc
Copy link
Author

Pezmc commented Oct 28, 2014

Hey lazyatom,

The file's definitely being written (was checking by reading the microsd with a usb adapter) but I agree the test could be more thorough! I'll add your suggestions (and anything else I can think of such as making web requests now and then perhaps, and writing 9185 bytes to it to match size the web response) when I get a free moment in the working week!

I was using 1.0.5 but was hitting the error so upgraded to 1.0.6, can rollback and try again with 1.0.5.

Thank you for your pointers!

@Pezmc
Copy link
Author

Pezmc commented Oct 28, 2014

I think I've demonstrated that either:

  • A: there's something wrong with my Arduino, or
  • B: file's can't be written to the SD card after or during a web client request

Does anyone mind trying it with their Arduino and reporting back?

New Test Script: https://gist.github.com/Pezmc/7862e20d9dd952993f64

Output with 1.0.6:

Initializing SD card...card initialized.
Setting up network
Got ethernet
IP: 192.168.2.2
Deleted Log.txt
Total (bytes) written to Log.txt was 9185
All went well so trying to download google.com
Connected
Failed to write to SD card: Go.html
Trying to write again now the client is stopped
The test with the client stopped failed to create: Go.html
Trying again in 5 seconds
Deleted Log.txt
Total (bytes) written to Log.txt was 9185
All went well so trying to download google.com
Connected
Failed to write to SD card: Go.html
Trying to write again now the client is stopped
The test with the client stopped failed to create: Go.html
Trying again in 5 seconds
Deleted Log.txt
... It stalled and never got any further than this ...

Output with 1.0.5:

Initializing SD card...card initialized.
Setting up network
Got ethernet
IP: 192.168.2.2
Deleted Log.txt
Log.txt was 0
All went well so trying to download google.com
Connected
Failed to write to SD card: Go.html
Trying to write again now the client is stopped
The test with the client stopped failed to create: Go.html
Trying again in 5 seconds
Log.txt
Log.txt was 0
All went well so trying to download google.com
Connected
Failed to write to SD card: Go.html
Trying to write again now the client is stopped
The test with the client stopped failed to create: Go.html
Trying again in 5 seconds
Log.txt
Log.txt was 0
All�R+�¥�±¥é¥¹��SD card...card initialized.
Setting up network
Got ethernet
IP: 192.168.2.2
Deleted Log.txt
Total (bytes) written to Log.txt was 33686018
All went well so trying to download google.com
Connected
Failed to write to SD card: Go.html
Trying to write again now the client is stopped
The test with the client stopped failed to create: Go.html
Trying again in 5 seconds
Deleted Log.txt
Total (bytes) written to Log.txt was 33686018

Output with 1.5.7:

Initializing SD card...card initialized.
Setting up network
Got ethernet
IP: 192.168.2.2
Deleted Log.txt
Failed to write to SD card: Log.txt
Trying again in 5 seconds
Deleted Log.txt
Failed to write to SD card: Log.txt
Trying again in 5 seconds
Deleted Log.txt
Failed to write to SD card: Log.txt
Trying again in 5 seconds
Deleted Log.txt
Failed to write to SD card: Log.txt
Trying again in 5 seconds
Deleted Log.txt
Failed to write to SD card: Log.txt

@juliensnz
Copy link

Hi @Pezmc,

did you find a solution ?

I get the exact same error :/

Regards,

Julien

@Pezmc
Copy link
Author

Pezmc commented Feb 7, 2015

Hi Julien, no I was never able to track down the exact issue, even with several days worth of tweaking!

@juliensnz
Copy link

Hi @Pezmc,

So you just abandoned the idea of doing this project or did you use another sd card or an other ethernet shield ?

Really sad to not be able to work this out :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants