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.
1 Answer
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)));
1 Comment
user203319
I don't know why this question and answer were downvoted, the StreamHttpClient example is indeed broken, and doesn't work without this fix, however there's a mistake, it should be
WiFiClient stream = http.getStream(); (. instead of ->)