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

WiFiClient.available() returns 0 after disconnect, even if there is data still in buffer #2147

Closed
rdowning-triax opened this issue Dec 3, 2018 · 2 comments
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@rdowning-triax
Copy link
Contributor

Hardware:

Board: ESP32 Gateway
Core Installation/update date: latest dev
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: ?no?
Upload Speed: 115200
Computer OS: Windows 10

Description:

When trying to stream a wificlient request content to serial, the end of the request data is lost because available() returns 0 once the client disconnects, even if there is still data to be read from the buffer. When running the program below, you can see the output never gets all the way to the end "</html>" tag.

Sketch: (leave the backquotes for code formatting)

#include <ssl_client.h>
#include <WiFiClientSecure.h>
#include <WiFi.h>

//#define USE_SECURE
#ifdef USE_SECURE
#define PORT 443
#else
#define PORT 80
#endif

void testClient(const char * host, uint16_t port)
{
  Serial.print("\nconnecting to ");
  Serial.println(host);

#ifdef USE_SECURE
  WiFiClientSecure client;
#else
  WiFiClient client;
#endif
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    return;
  }
  client.setTimeout(1000);
  client.print("GET / HTTP/1.0\r\n\r\n");
  while (client.connected() || client.available()) {
    if (client.available()) {
      Serial.write(client.read());
    } 
//    else {
//      Serial.println("F");
//    }
  }

  Serial.println("\n\nclosing connection\n");
  client.stop();
}

void setup()
{
  Serial.begin(115200);
  WiFi.begin(NETWORK, PASSWORD);
  Serial.print("connecting to wifi");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

}


void loop()
{
  testClient("google.com", PORT);

  delay(10000);
}

Debug Messages:

Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here 
rdowning-triax added a commit to rdowning-triax/arduino-esp32 that referenced this issue Dec 3, 2018
…re is still data in the buffer. Otherwise, how would we know it was there?
me-no-dev pushed a commit that referenced this issue Dec 4, 2018
…ll data in the buffer. Otherwise, how would we know it was there? (#2148)
@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

1 participant