#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#define WIFI_SSID "ssid"
#define WIFI_PASSWORD "password"
void setup() {
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
////////////////////////////////////////////
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient http;
http.begin(*client, "https://jsonplaceholder.typicode.com/photos");
http.addHeader("Accept", "*/*");
int httpCode = http.GET();
Serial.print("HTTP CODE: "); Serial.println(httpCode);
//reading response with buffer
static char buff[128] = { 0 };
while (http.connected() ) {
size_t size = client->available();
if (size) {
int c = client->readBytes(buff, ((size > sizeof(buff) ) ? sizeof(buff) : size));
//if i uncomment this next line, everything is fine.
//Serial.write(buff, c); Serial.println();
//but if i dont use serial.write program never gets here
if (char * pch = strstr (buff, "quis fuga")) {
char str[20] = { 0 }; int g = 0 ;
while (pch[g] != '\"') {
str[g] = pch[ g];
g++;
}
Serial.print("FOUND IT: "); Serial.println(str);
}
}
else if (!size) {
Serial.println( "reading done");
break;
}
delay(1);
}
}
void loop() {
delay(222222);
}
EDIT
here i created a compilable runnable code. basically i am trying to find a word in a http response. my real examples response isnt json and it is as long as this examples response. one other problem is i cant read all of the repsponse. it unexpectedly finishes reading sometimes after a few lines sometimes after a few hundred. in this particular request my nodemcu cant read after id 258. or id 8. object in the json response: https://jsonplaceholder.typicode.com/photos
if i dont use serial.write print buffer content, it finishes reading immideatly and thats exactly where i have the problem.