Closed
Description
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
Activity
espressif#2147 available() shouldn't return 0 after disconnect if the…
#2147 available() shouldn't return 0 after disconnect if there is sti…
stale commentedon 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 commentedon Aug 15, 2019
This stale issue has been automatically closed. Thank you for your contributions.