Parag Thakur
Parag Thakur

Reputation: 323

ESP8266 StreamHttpClient example broken - prints "read timeout" error

Problem: The ESP8266 example sketch StreamHttpClient, seems to be broken for 3.1.x version of the Arduino SDK. The URL is broken because it returns HTTP code 301. However, even if you fix the URL, the subsequent read from the stream fails and it prints "read timeout" error.

Upvotes: -1

Views: 57

Answers (1)

Parag Thakur
Parag Thakur

Reputation: 323

The current sketch uses some outdated code.

Current Sketch Code: (Broken)

// get tcp stream WiFiClient* stream = &client;

This no longer works. The following call returns 0 and does not populate any data and you get "read timeout" error: int c = stream->readBytes(buff, std::min((size_t)len, sizeof(buff)));

Correct Code:

WiFiClient stream = http->getStream();

int c = stream.readBytes(buff, std::min((size_t)len, sizeof(buff)));

Upvotes: -1

Related Questions