Skip to content

WiFiClientSecure hangs on Files > 48k bytes #4824

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

Closed
ZinggJM opened this issue Jun 18, 2018 · 1 comment
Closed

WiFiClientSecure hangs on Files > 48k bytes #4824

ZinggJM opened this issue Jun 18, 2018 · 1 comment

Comments

@ZinggJM
Copy link

ZinggJM commented Jun 18, 2018

----------------------------- Delete below -----------------------------

----------------------------- Delete above -----------------------------

Basic Infos

  • [x ] This issue complies with the issue POLICY doc.
  • [x ] I have read the documentation at readthedocs and the issue is not addressed there.
  • [x ] I have tested that the issue is present in current master branch (aka latest git).
  • [x ] I have searched the issue tracker for a similar issue.
  • [x ] If there is a stack dump, I have decoded it.
  • [ x] I have filled out all fields below.

Platform

  • Hardware: ESP8266 device
  • Core Version: 2.4.1
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Wemos D1 mini r2
  • Flash Mode: ?
  • Flash Size: 4MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: ?
  • Flash Frequency: [40Mhz]
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

download from Web-page through WiFiClientSecure hangs for large files

MCVE Sketch

/*
    HTTP over TLS (HTTPS) example sketch

    This example demonstrates how to use
    WiFiClientSecure class to access HTTPS API.
    We fetch and display the status of
    esp8266/Arduino project continuous integration
    build.

    Limitations:
      only RSA certificates
      no support of Perfect Forward Secrecy (PFS)
      TLSv1.2 is supported since version 2.4.0-rc1

    Created by Ivan Grokhotkov, 2015.
    This example is in public domain.
*/

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

const char* ssid = "........";
const char* password = "........";

//const char* host = "api.github.com";
const char* host = "raw.githubusercontent.com";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
//const char* fingerprint = "35 85 74 EF 67 35 A7 CE 40 69 50 F3 C0 F6 80 CF 80 3B 2E 19";
const char* fingerprint     = "cc aa 48 48 66 46 0e 91 53 2c 9c 7c 23 2a b1 74 4d 29 9d 33";

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.print("connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Use WiFiClientSecure class to create TLS connection
  WiFiClientSecure client;
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }

  //String url = "/repos/esp8266/Arduino/commits/master/status";
  //String url = "/prenticedavid/MCUFRIEND_kbv/master/extras/bitmaps/betty_1.bmp"; // works
  String url = "/prenticedavid/MCUFRIEND_kbv/master/extras/bitmaps/test.bmp"; // hangs
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");

  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  //  String line = client.readStringUntil('\n');
  //  if (line.startsWith("{\"state\":\"success\"")) {
  //    Serial.println("esp8266/Arduino CI successfull!");
  //  } else {
  //    Serial.println("esp8266/Arduino CI has failed");
  //  }
  //  Serial.println("reply was:");
  //  Serial.println("==========");
  //  Serial.println(line);
  //  Serial.println("==========");
  //  Serial.println("closing connection");
  uint32_t count = 0;
  while (client.connected())
  {
    if (client.available())
    {
      int16_t v = client.read();
      count++;
      if (0 == count % 1000)
      {
        Serial.print("got "); Serial.print(count); Serial.println(" so far...");
        delay(1); // avoid WDT
      }
    }
    else delay(1); // avoid WDT
  // hangs after 48000
  }
  Serial.print("terminated, received "); Serial.println(count);
}

void loop() {
}

Debug Messages

Debug messages go here
@d-a-v
Copy link
Collaborator

d-a-v commented Jun 18, 2018

Your #4814 is already reopened. Thanks for the provided details and MCVE !

@d-a-v d-a-v closed this as completed Jun 18, 2018
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

2 participants