Post about your Basic project here

Moderator: Mmiscool

User avatar
By robcim
#80099 Hi all,
I must download a json file (180kB) from a server and I must do its parser. I use an esp8266 with Arduino IDE using the HTTPClient.h library and its examples.
The instructions used are http.GET() and http.GetString(). The GET give me a result ok (=200) but the getString return a empty string. Why? Because the file it's big? There are a solutions?
Can you help me please?
Thank you.
User avatar
By Pablo2048
#80130
QuickFix wrote:Somehow your failing code was magically erased from the forum, please post it again. :idea:

He probably didn't post any code. It seems like he didn't realize that 180kB JSON doesn't fit to CPU which has totally 80kB RAM so .getString() method ends with OOM... Solution: chunked/streaming transfer and streaming JSON parser ;-) ...
User avatar
By robcim
#80132
QuickFix wrote:Somehow your failing code was magically erased from the forum, please post it again. :idea:

1° Test:
File f = SPIFFS.open("/f.xml", "w");
http.begin(Link);
httpCode = http.GET();
if ((httpCode==200)){
f.println(http.getString());
f.close();
f = SPIFFS.open("/f.json", "r");
if (!f) {
Serial.println("file open failed");
}
String s1=f.readString();
Result 1°Test: httpCode=200 ( OK) but the string s1 it's empty. If I download a small file the string s1 it's ok.

2° Test:
File f = SPIFFS.open("/f.json", "w");
// if (f) {
http.begin(Link);
httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
unsigned long t=millis();
http.writeToStream(&f);
unsigned long tempo=millis()-t;
Serial.print("tempo impiegato=");Serial.println(tempo);
delay(50);
f.close();
f = SPIFFS.open("/f.json", "r");
String s;
for (int i=1; i<=11000; i++){
s=f.readStringUntil(',');
}
f.close();
}
}
http.end();
Result 2°Test: httpCode=200 ( OK) and I can read all.
So, I could use the 2° code and download the entire file but How Can I do the parse json file?