I've googled this and lots of people seem to have problems with this, but nowhere have I found a solution. I have a NodeMcu V3 ESP8266. I'm trying to read a page, which is generated by a PHP script. The page looks fine in a browser. It outputs something like this:
Das klinget so herrlich 1: 0, 93, 80,
2: -116, 0, 0,
3: 240, 91, 80,
4: 480, 74, 80,
5: 480, 78, 80,
6: 480, 81, 80,
7: 480, 90, 80,
8: 960, 98, 80,
9: 1440, 102, 80,
10: 1920, 93, 80,
11: 2160, 90, 80,
12: 2400, 81, 80,
13: 2400, 85, 80,
Plain text. Sometimes https.getString(); returns the right content, but mostly it returns nothing. Typical output in my Serial windows is:
[HTTPS] begin...
[HTTPS] GET...
[HTTPS] GET... code: 200
Wait 10s before next round...
After the "code: 200" it should show the data listings, before the "Wait 10s...". I've tested several code examples, which should work with https. This is a part of my code:
HTTPClient https;
Serial.print("[HTTPS] begin...\n");
if (https.begin(*client, jigsaw_host, jigsaw_port)) { // HTTPS
Serial.print("[HTTPS] GET...\n");
// start connection and send HTTP header
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Unable to connect %d\n");
}
}
It hardly ever reaches the "failed, error" part, which means the GET() seems to work. Only the getString(); fails. I'm willing to test a completely different approach, if I only knew what. The getString() reads the whole page in one run, right? Has the failure anything to do with the size of the data chunk? Is there a way to read a web page line by line?