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

not all content is downloaded #27

Open
koulombus opened this issue Dec 8, 2017 · 0 comments
Open

not all content is downloaded #27

koulombus opened this issue Dec 8, 2017 · 0 comments

Comments

@koulombus
Copy link

koulombus commented Dec 8, 2017

I try to download a picture from web server and save to SD.
First what I see is a negative content length.
Content length is: -16328
Way?

The picture content starts with 0x42, 0x4D .... on start index 0.
ID: 0 0x42
ID: 1 0x4D
....
so far so good....

the while loop stops on index 49047 but the full size is 49207
image

Whats wrong with your example code?

here my code

    if (responseCode == 200) {
      responseCode = http.skipResponseHeaders();
      if (responseCode >= 0) {
        int bodyLen = http.contentLength();

        Serial.print("Content length is: ");
        Serial.println(bodyLen);

        unsigned long timeoutStart = millis();
        char c;
        long i = 0;
        // Whilst we haven't timed out & haven't reached the end of the body
        while ( (http.connected() || http.available()) &&
                ((millis() - timeoutStart) < 30000) ) {

          if (http.available()) {
            c = http.read();

            Serial.print("ID: ");
            Serial.print(i);
            Serial.print("\t");
            Serial.print(c);
            Serial.print("\t");
            Serial.println(c, HEX);

            i++;
            myFile.print(c);
            bodyLen--;
            // We read something, reset the timeout counter
            timeoutStart = millis();
          }
          else
          {
            // We haven't got any data, so let's pause to allow some to arrive.
            wait(1000);
          }
        }

        if (!http.connected()) {
          Serial.println("disconnecting.");
          http.stop();
          myFile.close();
          Serial.println("Finished writing to file");
        }
      }
    }
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

1 participant