Modifiying Parse json - unable to get it work

Hello!
I started messing with Arduino because of curiosity and wanting to learn something about something new. I have no programming skills. Nothing. I just started reading Arduino sample codes and tried to figure out how they worked.
I tried to do modifications to see if I could adapt them to my needs and little by little I got to do various things.

I set out to do a meteorological station with a small Oled screen and I got it, but it did not seem like much to me, so I decided to do another one with a colour LCD with touch-screen. It is almost finished. I could say that it is. But I have a big free space in the second screen, and here is where I don´t have the knowledge to program what I want to show in it.
If someone wanted to help me to solve the code I would be very happy.

Without entering in unuseful details I’ll explain the assembly:

The station consists in one Arduino Mega (the sketch is so long that I could not fit it into a Uno), a temperature, humidity and pressure sensor BME280, a WiFi module ESP8266-01 and a logic converter to communicate the WiFi low-voltage module with the Mega.
At boot time 3 data requests are made through the Wunderground servers to a station located very close to my house. A current conditions request, a forecast request and a lunar phase request. All this is done with AT commands sent to the WiFi module.

The main screen shows the current data of indoor temperature and humidity, outdoor temperature and humidity, current weather (with icon), current wind speed (with icon), moon phase (with icon) and sunrise-sunset - moonrise-moonset.
Touching the screen it switches to screen 2, which shows the weather forecast for today, tomorrow and the day after tomorrow (with icons), minimum and maximum temperatures and probability of rain. There is also a touch button at the bottom to force an update of all the parameters, in case that the initial Parse had failed (sometimes it happens, the parse fails or stops, and I do not know why).
That is the basics of the station.


I could leave it like this, but on the second screen I have a free space of almost half screen, and I would like to add 3 more strings of information provided by Wunderground, but I do not know how to modify the Parse method for it. I have tried and tried to modify the code without knowing very well what I am doing, and I am already desperate not to get results. In the Parse process I always get the message “ParseObject () has failed”.
Attached picture is a complete capture of what I receive from Wunderground when doing request. Blue-marked are the chains that I currently read and use. Red-marked are the 3 strings that I want to read and I don´t know how to do it, of course, adding the reading of the blue ones too.

And here are the parts of code that I currently use (and that would need to be modified):

...

#include <ArduinoJson.h>
#define wifi Serial1

...

char* forecast[] = {"\"weekday\":", "\"celsius\":", "\"celsius\":", "\"icon\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"icon\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"icon\":", "\"pop\":"};
int num_elements_fr = 15;  // number of elements for the forecast array
char* forecast_rename[] = {"\"day_0\":", "\"high_0\":", "\"low_0\":", "\"icon_0\":", "\"pop_0\":", "\"day_1\":", "\"high_1\":", "\"low_1\":", "\"icon_1\":", "\"pop_1\":", "\"day_2\":", "\"high_2\":", "\"low_2\":", "\"icon_2\":", "\"pop_2\":"}; //rename for each different day

const int buffer = 400;           // length of json buffer
char close_brace = '}';              // neccessary for parse
char comma = ',';                    // neccessary for parse


const char* day0;                    // array prevision Wunderground
float high0;                         // array prevision Wunderground
float low0;                          // array prevision Wunderground
float pop_0;                         // array prevision Wunderground
const char* icono0;                  // array prevision Wunderground
const char* day1;                    // array prevision Wunderground
float high1;                         // array prevision Wunderground
float low1;                          // array prevision Wunderground
float pop_1;                         // array prevision Wunderground
const char* icono1;                  // array prevision Wunderground
const char* day2;                    // array prevision Wunderground
float high2;                         // array prevision Wunderground
float low2;                          // array prevision Wunderground
float pop_2;                         // array prevision Wunderground
const char* icono2;                  // array prevision Wunderground

...


void setup() {
  wifi.begin(57600);
  wifi.setTimeout(5000);
  Serial.begin(57600);
  
  ...

  // try to connect to wifi
  boolean connected = false;
  for (int i = 0; i < 5; i++) {
    if (connectWiFi()) {
      connected = true;

      ...

      updatePrevision();
      break;
    }
  }
}


void loop() {

...

}



void updatePrevision() {
  retry:

    ...

    wifi.flush();
    wifi.println("AT+CIPSTART=\"TCP\",\"23.222.152.140\",80");
    if (wifi.find("Error")) return;
    
                              // (My API)                         (direct station)
    String cmd2 = "GET /api/XXXXXXXXXXXXXXXX/forecast/lang:SP/q/pws:ILANGREO3.json HTTP/1.1\r\nHost: api.wunderground.com\r\n\r\n";
    wifi.print("AT+CIPSEND=");
    wifi.println(cmd2.length());
    delay(2000);
    if (wifi.find(">")) {
      Serial.print(F(">>"));
    } else {
      wifi.println(F("AT+CIPCLOSE"));
      Serial.println(F("Fail"));
      delay(2000);
      goto retry;
    }
    wifi.print(cmd2);
    unsigned int i = 0; //timeout counter
    char json[buffer] = "{"; // array for Json parsing
    int n = 1;          // character counter for json
    while (!wifi.find("\"simpleforecast\": {")) {}
    for (int j = 0; j < num_elements_fr; j++) {
      while (!wifi.find(forecast[j])) {} // find the part we are interested in.
      String Str1 = forecast_rename[j];
      for (int l = 0; l < (Str1.length()); l++) {
        json[n] = Str1[l];
        n++;
      }
      Serial.print(".");
      while (i < 60000) {
        if (wifi.available()) {
          char c = wifi.read();
          if (c == ',') {
            break;
          }
          if (c == '}') {
            n--;
            n--;
            n--;
            break;
          }
          json[n] = c;
          n++;
          i = 0;
        }
        i++;
      }
      if (j == num_elements_fr - 1) {
        json[n] = close_brace;
      } else {
        json[n] = comma;
      }
      n++;
    }
    parseForecastJSON(json);
    Serial.print("/ ");
    wifi.println("AT+CIPCLOSE");
    delay(2000);

    ...

}


void parseForecastJSON(char json[400]) {
  StaticJsonBuffer<buffer> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(json);
  if (!root.success()) {
    Serial.println(F("parseObject() failed"));
    wifi.println(F("AT+CIPCLOSE"));
    delay(2000);
    updatePrevision();
  }

  day0   = root["day_0"];
  high0  = root["high_0"];
  low0   = root["low_0"];
  icono0 = root["icon_0"];
  pop_0  = root["pop_0"];
  day1   = root["day_1"];
  high1  = root["high_1"];
  low1   = root["low_1"];
  icono1 = root["icon_1"];
  pop_1  = root["pop_1"];
  day2   = root["day_2"];
  high2  = root["high_2"];
  low2   = root["low_2"];
  icono2 = root["icon_2"];
  pop_2  = root["pop_2"];

  
}

...

I have to beg for help because I know I won´t be able to solve this problem on my own. I read some documentation about that but I don´t understand it, this problem is too big for me and my little knowledge.

Thanks in advance to anyone who wants to waste his time helping me.

Nobody?
Please, please, please. :confused:

dj_pole:
Nobody?
Please, please, please. :confused:

I started to post an answer,
...
but, too much snippage happened,
...
so I decided not to.

If you want help, you will post ALL of your code. You will add Serial.print() statements to show what it actually passed to the function that generates the error message, AND you will show is that output.

The whole code has about 1000 lines at this moment. I don´t know what need to get dizzy with code lines that handle the icons, or read the sensors or other functions that I’m still finally testing. That’s why I just wrote the code part with the problem.
So I’ll make it easier. I’ll use my test sketch. As I said, I have no programming skills, I have been with this project for 2 months, reading examples and trying to modify them for each function I need. So for each function I have a test sketch in which I work until I get working that part of the project. Then I include the code in the global project, the definitive one.

This is the sketch that tests the weather forecast request to the Wunderground servers and gives me the answer in the serial monitor. It works. Just change SSID, Password and the Wunderground API.

#include <Arduino.h>
#include <ArduinoJson.h>

#define wifi Serial1

// Now the array with the elements we want to get.
// They must be written in the same order received from Wunderground, or the parse won´t work.
char* forecast[] = {"\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":"};
int num_elements_fr = 12;  // number of elements in the array
char* forecast_rename[] = {"\"day_0\":", "\"high_0\":", "\"low_0\":", "\"pop_0\":", "\"day_1\":", "\"high_1\":", "\"low_1\":", "\"pop_1\":", "\"day_2\":", "\"high_2\":", "\"low_2\":", "\"pop_2\":"}; //elements rename for today, tommorrow and next day
const int buffer = 400;           // json buffer length
char close_brace = '}';           // neccessary for parse
char comma = ',';                 // neccessary for parse
const char* day0;                 // name for today
float high0;                      // high temp for today
float low0;                       // low temp for today
float pop0;                       // rain probability for today
const char* day1;                 // name for tomorrow
float high1;                      // high temp for tomorrow
float low1;                       // low temp for tomorrow
float pop1;                       // rain probability for tomorrow
const char* day2;                 // name for next day
float high2;                      // high temp for next day
float low2;                       // low temp for next day
float pop2;                       // rain probability for next day


void setup() {
  wifi.begin(57600);
  wifi.setTimeout(5000);
  Serial.begin(57600);
  boolean connected = false;      // try to connect to wifi
  for (int i = 0; i < 5; i++) {
    if (connectWiFi()) {
      connected = true;
      Serial.println("Loop start");
      break;
    }
  }
}


void loop() {
updatePrevision();  // this local station updates the prevision each 60 minutes. 
delay(60000);       // Here we use 1 minute only for test purpose (check Wunderground query limit for free acounts)
}


boolean connectWiFi() {
  wifi.flush();
  wifi.println("AT+RST");
  wifi.setTimeout(4000);
  wifi.println(F("AT+CWMODE=1"));
  if (wifi.find("OK")) {
    Serial.println(F("ESP8266 mode1"));
    wifi.println(F("AT+CWJAP=\"MYSSID\",\"MYPASSWORD\"\r\n"));
    delay(10000);             // a bit of time for slow routers
  } else {
    Serial.println(F("ESP8266 not working"));
    connectWiFi();
  }
  wifi.println(F("AT+CIPSTATUS"));
  wifi.setTimeout(4000);
  if (wifi.find("OK")) {
    delay(1000);
    wifi.println(F("AT+CIPMUX=0"));
    delay(1000);
    if (wifi.find("OK")) {
      Serial.println(F("WiFi full configured"));
      return true;
      delay(1000);
    } else {
      Serial.println(F("Error configuring WiFi"));
      delay(500);
      return false;
    }
  }
}


void updatePrevision() {
    wifi.flush();
    wifi.println("AT+CIPSTART=\"TCP\",\"23.222.152.140\",80");  // connection with Wunderground server
    if (wifi.find("Error")) return;
                          //MyAPIKey (16 digits)
    String cmd2 = "GET /api/xxxxxxxxxxxxxxxx/forecast/lang:SP/q/pws:ILANGREO3.json HTTP/1.1\r\nHost: api.wunderground.com\r\n\r\n";
    wifi.print("AT+CIPSEND=");
    wifi.println(cmd2.length());   // sends to server the lenght of the query
    delay(2000);
    if (wifi.find(">")) {
      Serial.print(F(">>"));       // checks OK response from server
    } else {
      wifi.println(F("AT+CIPCLOSE"));
      Serial.println(F("Connection time has expired"));
      delay(2000);
      updatePrevision();
    }
    wifi.print(cmd2);                       // query to server
    unsigned int i = 0; //timeout counter
    char json[buffer] = "{"; // array for Json parsing
    int n = 1;          // character counter for json
    while (!wifi.find("\"simpleforecast\": {")) {}
    for (int j = 0; j < num_elements_fr; j++) {
      while (!wifi.find(forecast[j])) {} // find the part we are interested in.
      String Str1 = forecast_rename[j];
      for (int l = 0; l < (Str1.length()); l++) {
        json[n] = Str1[l];
        n++;
      }
      Serial.print(".");            // checking parse. Should see one dot for each element in the array
      while (i < 60000) {
        if (wifi.available()) {
          char c = wifi.read();
          if (c == ',') {
            break;
          }
          if (c == '}') {
            n--;
            n--;
            n--;
            break;
          }
          json[n] = c;
          n++;
          i = 0;
        }
        i++;
      }
      if (j == num_elements_fr - 1) {
        json[n] = close_brace;
      } else {
        json[n] = comma;
      }
      n++;
    }
    parseForecastJSON(json);
    Serial.println("/");             // confirmation for parse finish
    wifi.println("AT+CIPCLOSE");     // at this point you should see "............/" in serial monitor (12 dots + /)
    delay(1000);
    Serial.println("");
    Serial.println("WEATHER PREVISION");
    Serial.print(day0); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high0); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low0); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop0); Serial.println("%");
    Serial.print(day1); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high1); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low1); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop1); Serial.println("%");
    Serial.print(day2); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high2); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low2); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop2); Serial.println("%");

}


void parseForecastJSON(char json[400]) {
  StaticJsonBuffer<buffer> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(json);
  if (!root.success()) {
    Serial.println(F("parseObject() failed"));
    wifi.println(F("AT+CIPCLOSE"));
    delay(2000);
    updatePrevision();
  }

  day0   = root["day_0"];
  high0  = root["high_0"];
  low0   = root["low_0"];
  pop0  = root["pop_0"];
  day1   = root["day_1"];
  high1  = root["high_1"];
  low1   = root["low_1"];
  pop1  = root["pop_1"];
  day2   = root["day_2"];
  high2  = root["high_2"];
  low2   = root["low_2"];
  pop2  = root["pop_2"];
}

What I get on the serial monitor is this:

ESP8266 mode 1
WiFi full configured
Loop start

…/

WEATHER PREVISION
Viernes: High temp 21.00°C Low temp: 15.00°C Chance of rain 10.00%
Sábado: High temp 17.00°C Low temp: 13.00°C Chance of rain 90.00%
Domingo: High temp 19.00°C Low temp: 16.00°C Chance of rain 20.00%

(CONTINUE)

The answer I get from Wunderground if I write it directly in Chrome is this:

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "forecast": 1
  }
	}
		,
	"forecast":{
		"txt_forecast": {
		"date":"12:35 AM CEST",
		"forecastday": [
		{
		"period":0,
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"title":"Viernes",
		"fcttext":"Cielo parcialmente cubierto. Máxima de 75 F. Vientos del ONO y variable.",
		"fcttext_metric":"Cielo parcialmente cubierto. Máxima de 24 C. Vientos del ONO y variable.",
		"pop":"0"
		}
		,
		{
		"period":1,
		"icon":"nt_rain",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_rain.gif",
		"title":"Noche del viernes",
		"fcttext":"Formación de lluvias a última hora. Mínima de 56 F. Vientos del O de 10 a 15 milla/h. 100% probab. de lluvia.",
		"fcttext_metric":"Formación de lluvias a última hora. Mínima de 13 C. Vientos del O de 10 a 15 km/h. 100% probab. de lluvia.",
		"pop":"100"
		}
		,
		{
		"period":2,
		"icon":"rain",
		"icon_url":"http://icons.wxug.com/i/c/k/rain.gif",
		"title":"Sábado",
		"fcttext":"Lluvia. Más fresco. Máxima de 61 F. Vientos del ONO de 5 a 10 milla/h. 100% probab. de lluvia. Lluvias de unos 0.5 pulgada.",
		"fcttext_metric":"Lluvia. Más fresco. Máxima de 16 C. Vientos del ONO de 10 a 15 km/h. 100% probab. de lluvia. Lluvias de unos 12 mm.",
		"pop":"100"
		}
		,
		{
		"period":3,
		"icon":"nt_rain",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_rain.gif",
		"title":"Noche del sábado",
		"fcttext":"Lluvia. Mínima de 53 F. Vientos del O de 5 a 10 milla/h. 100% probab. de lluvia. Lluvias de unos 0.25 pulgada.",
		"fcttext_metric":"Lluvia. Mínima de 11 C. Vientos del O de 10 a 15 km/h. 100% probab. de lluvia. Lluvias de unos 6 mm.",
		"pop":"100"
		}
		,
		{
		"period":4,
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"title":"Domingo",
		"fcttext":"Chubascos matinales. Máxima de 69 F. Vientos del O de 5 a 10 milla/h. 30% probab. de lluvia.",
		"fcttext_metric":"Chubascos matinales. Máxima de 20 C. Vientos del O de 10 a 15 km/h. 30% probab. de lluvia.",
		"pop":"30"
		}
		,
		{
		"period":5,
		"icon":"nt_chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_chancerain.gif",
		"title":"Noche del domingo",
		"fcttext":"Chubascos de madrugada. Mínima de 59 F. Vientos del SO y variable. 50% probab. de lluvia.",
		"fcttext_metric":"Chubascos de madrugada. Mínima de 15 C. Vientos del SO y variable. 50% probab. de lluvia.",
		"pop":"50"
		}
		,
		{
		"period":6,
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"title":"Lunes",
		"fcttext":"Chubascos matinales. Máxima de 67 F. Vientos del ONO de 10 a 15 milla/h. 50% probab. de lluvia.",
		"fcttext_metric":"Chubascos matinales. Máxima de 19 C. Vientos del ONO de 10 a 15 km/h. 50% probab. de lluvia.",
		"pop":"50"
		}
		,
		{
		"period":7,
		"icon":"nt_mostlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/nt_mostlycloudy.gif",
		"title":"Noche del lunes",
		"fcttext":"Cielo prácticamente cubierto. Mínima de 54 F. Vientos del OSO de 5 a 10 milla/h.",
		"fcttext_metric":"Cielo prácticamente cubierto. Mínima de 12 C. Vientos del OSO de 10 a 15 km/h.",
		"pop":"20"
		}
		]
		},
		"simpleforecast": {
		"forecastday": [
		{"date":{
	"epoch":"1504890000",
	"pretty":"7:00 PM CEST en Septiembre 08, 2017",
	"day":8,
	"month":9,
	"year":2017,
	"yday":250,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"Septiembre",
	"monthname_short":"Sep",
	"weekday_short":"Vie",
	"weekday":"Viernes",
	"ampm":"PM",
	"tz_short":"CEST",
	"tz_long":"Europe/Madrid"
},
		"period":1,
		"high": {
		"fahrenheit":"75",
		"celsius":"24"
		},
		"low": {
		"fahrenheit":"56",
		"celsius":"13"
		},
		"conditions":"Parcialmente nublado",
		"icon":"partlycloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"skyicon":"",
		"pop":0,
		"qpf_allday": {
		"in": 0.18,
		"mm": 5
		},
		"qpf_day": {
		"in": 0.00,
		"mm": 0
		},
		"qpf_night": {
		"in": 0.18,
		"mm": 5
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "ONO",
		"degrees": 293
		},
		"avewind": {
		"mph": 5,
		"kph": 8,
		"dir": "ONO",
		"degrees": 293
		},
		"avehumidity": 72,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1504976400",
	"pretty":"7:00 PM CEST en Septiembre 09, 2017",
	"day":9,
	"month":9,
	"year":2017,
	"yday":251,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"Septiembre",
	"monthname_short":"Sep",
	"weekday_short":"Sáb",
	"weekday":"Sábado",
	"ampm":"PM",
	"tz_short":"CEST",
	"tz_long":"Europe/Madrid"
},
		"period":2,
		"high": {
		"fahrenheit":"61",
		"celsius":"16"
		},
		"low": {
		"fahrenheit":"53",
		"celsius":"12"
		},
		"conditions":"Lluvia",
		"icon":"rain",
		"icon_url":"http://icons.wxug.com/i/c/k/rain.gif",
		"skyicon":"",
		"pop":100,
		"qpf_allday": {
		"in": 0.72,
		"mm": 18
		},
		"qpf_day": {
		"in": 0.44,
		"mm": 11
		},
		"qpf_night": {
		"in": 0.29,
		"mm": 7
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "ONO",
		"degrees": 284
		},
		"avewind": {
		"mph": 9,
		"kph": 14,
		"dir": "ONO",
		"degrees": 284
		},
		"avehumidity": 90,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1505062800",
	"pretty":"7:00 PM CEST en Septiembre 10, 2017",
	"day":10,
	"month":9,
	"year":2017,
	"yday":252,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"Septiembre",
	"monthname_short":"Sep",
	"weekday_short":"Dom",
	"weekday":"Domingo",
	"ampm":"PM",
	"tz_short":"CEST",
	"tz_long":"Europe/Madrid"
},
		"period":3,
		"high": {
		"fahrenheit":"69",
		"celsius":"21"
		},
		"low": {
		"fahrenheit":"59",
		"celsius":"15"
		},
		"conditions":"Probabilidad de lluvia",
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"skyicon":"",
		"pop":30,
		"qpf_allday": {
		"in": 0.03,
		"mm": 1
		},
		"qpf_day": {
		"in": 0.02,
		"mm": 1
		},
		"qpf_night": {
		"in": 0.02,
		"mm": 1
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 10,
		"kph": 16,
		"dir": "O",
		"degrees": 270
		},
		"avewind": {
		"mph": 7,
		"kph": 11,
		"dir": "O",
		"degrees": 270
		},
		"avehumidity": 76,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		,
		{"date":{
	"epoch":"1505149200",
	"pretty":"7:00 PM CEST en Septiembre 11, 2017",
	"day":11,
	"month":9,
	"year":2017,
	"yday":253,
	"hour":19,
	"min":"00",
	"sec":0,
	"isdst":"1",
	"monthname":"Septiembre",
	"monthname_short":"Sep",
	"weekday_short":"Lun",
	"weekday":"Lunes",
	"ampm":"PM",
	"tz_short":"CEST",
	"tz_long":"Europe/Madrid"
},
		"period":4,
		"high": {
		"fahrenheit":"67",
		"celsius":"19"
		},
		"low": {
		"fahrenheit":"54",
		"celsius":"12"
		},
		"conditions":"Probabilidad de lluvia",
		"icon":"chancerain",
		"icon_url":"http://icons.wxug.com/i/c/k/chancerain.gif",
		"skyicon":"",
		"pop":50,
		"qpf_allday": {
		"in": 0.06,
		"mm": 2
		},
		"qpf_day": {
		"in": 0.06,
		"mm": 2
		},
		"qpf_night": {
		"in": 0.00,
		"mm": 0
		},
		"snow_allday": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_day": {
		"in": 0.0,
		"cm": 0.0
		},
		"snow_night": {
		"in": 0.0,
		"cm": 0.0
		},
		"maxwind": {
		"mph": 15,
		"kph": 24,
		"dir": "ONO",
		"degrees": 294
		},
		"avewind": {
		"mph": 10,
		"kph": 16,
		"dir": "ONO",
		"degrees": 294
		},
		"avehumidity": 81,
		"maxhumidity": 0,
		"minhumidity": 0
		}
		]
		}
	}
}

As you can see, the data match perfectly with the received in the serial monitor. Same temperatures, same chance of rain, no extrange characters or symbols... Seems to work fine. (Well, there´s a problem with spanish accents in two days of the week, but that will be another war, first try to win this one).

(CONTINUE)

The problem comes now, with the new data I want to add to the request. For testing this I wrote another sketch requesting only this new data, and if I could read it then try in another sketch to add the new data to the previous one that I have already managed to read.
But I have not even managed to read this new one alone. And of course neither to add it to the old data.
The sketch I have made and that doesn´t work is this: (I have tried more variants, same negative result)

#include <Arduino.h>
#include <ArduinoJson.h>

#define wifi Serial1

// Now the array with the elements we want to get.
// They must be written in the same order received from Wunderground, or the parse won´t work.

/* original working code
char* forecast[] = {"\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":", "\"weekday\":", "\"celsius\":", "\"celsius\":", "\"pop\":"};
int num_elements_fr = 12;  // number of elements in the array
char* forecast_rename[] = {"\"day_0\":", "\"high_0\":", "\"low_0\":", "\"pop_0\":", "\"day_1\":", "\"high_1\":", "\"low_1\":", "\"pop_1\":", "\"day_2\":", "\"high_2\":", "\"low_2\":", "\"pop_2\":"}; //elements rename for today, tommorrow and next day
const int buffer = 400;           // json buffer length
char close_brace = '}';           // neccessary for parse
char comma = ',';                 // neccessary for parse
const char* day0;                 // name for today
float high0;                      // high temp for today
float low0;                       // low temp for today
float pop0;                       // rain probability for today
const char* day1;                 // name for tomorrow
float high1;                      // high temp for tomorrow
float low1;                       // low temp for tomorrow
float pop1;                       // rain probability for tomorrow
const char* day2;                 // name for next day
float high2;                      // high temp for next day
float low2;                       // low temp for next day
float pop2;                       // rain probability for next day
*/
char* forecast[] = {"\"fcttext_metric\":", "\"fcttext_metric\":", "\"fcttext_metric\":", "\"fcttext_metric\":", "\"fcttext_metric\":"};
int num_elements_fr = 5;  // number of elements in the array
char* forecast_rename[] = {"\"text_0\":", "\"":", "\"text_1\":", "\"":", "\"text_2\":"}; //elements rename for today,(night nothing), tommorrow,(night nothing) and next day
const int buffer = 400;           // json buffer length
char close_brace = '}';           // neccessary for parse
char comma = ',';                 // neccessary for parse
const char* text0;                // text for today
const char* text1;                // text for tomorrow
const char* text2;                // text for next day



void setup() {
  wifi.begin(57600);
  wifi.setTimeout(5000);
  Serial.begin(57600);
  boolean connected = false;      // try to connect to wifi
  for (int i = 0; i < 5; i++) {
    if (connectWiFi()) {
      connected = true;
      Serial.println("Loop start");
      break;
    }
  }
}


void loop() {
updatePrevision();  // this local station updates the prevision each 60 minutes. 
delay(60000);       // Here we use 1 minute only for test purpose (check Wunderground query limit for free acounts)
}


boolean connectWiFi() {
  wifi.flush();
  wifi.println("AT+RST");
  wifi.setTimeout(4000);
  wifi.println(F("AT+CWMODE=1"));
  if (wifi.find("OK")) {
    Serial.println(F("ESP8266 mode 1"));
    wifi.println(F("AT+CWJAP=\"MYSSID\",\"MYPASSWORD\"\r\n"));   // Change SSID and Pass
    delay(10000);             // a bit of time for slow routers
  } else {
    Serial.println(F("ESP8266 not working"));
    connectWiFi();
  }
  wifi.println(F("AT+CIPSTATUS"));
  wifi.setTimeout(4000);
  if (wifi.find("OK")) {
    delay(1000);
    wifi.println(F("AT+CIPMUX=0"));
    delay(1000);
    if (wifi.find("OK")) {
      Serial.println(F("WiFi full configured"));
      return true;
      delay(1000);
    } else {
      Serial.println(F("Error configuring WiFi"));
      delay(500);
      return false;
    }
  }
}


void updatePrevision() {
    wifi.flush();
    wifi.println("AT+CIPSTART=\"TCP\",\"23.222.152.140\",80");  // connection with Wunderground server
    if (wifi.find("Error")) return;
                          //MyAPIKey (16 digits)
    String cmd2 = "GET /api/xxxxxxxxxxxxxxxx/forecast/lang:SP/q/pws:ILANGREO3.json HTTP/1.1\r\nHost: api.wunderground.com\r\n\r\n";
    wifi.print("AT+CIPSEND=");
    wifi.println(cmd2.length());   // sends to server the lenght of the query
    delay(2000);
    if (wifi.find(">")) {
      Serial.print(F(">>"));       // checks OK response from server
    } else {
      wifi.println(F("AT+CIPCLOSE"));
      Serial.println(F("Connection time has expired"));
      delay(2000);
      updatePrevision();
    }
    wifi.print(cmd2);                       // query to server
    unsigned int i = 0; //timeout counter
    char json[buffer] = "{"; // array for Json parsing
    int n = 1;          // character counter for json
//  while (!wifi.find("\"simpleforecast\": {")) {}    // original working code - elements under "simpleforecast"
    while (!wifi.find("\"txt_forecast\": {")) {}      // elements under "txt_forecast" - here is where I think I have to look for the new elements "fcttext_metric"
    for (int j = 0; j < num_elements_fr; j++) {
      while (!wifi.find(forecast[j])) {} // find the part we are interested in.
      String Str1 = forecast_rename[j];
      for (int l = 0; l < (Str1.length()); l++) {
        json[n] = Str1[l];
        n++;
      }
      Serial.print(".");            // checking parse. Should see one dot for each element in the array
      while (i < 60000) {
        if (wifi.available()) {
          char c = wifi.read();
          if (c == ',') {
            break;
          }
          if (c == '}') {
            n--;
            n--;
            n--;
            break;
          }
          json[n] = c;
          n++;
          i = 0;
        }
        i++;
      }
      if (j == num_elements_fr - 1) {
        json[n] = close_brace;
      } else {
        json[n] = comma;
      }
      n++;
    }
    parseForecastJSON(json);
    Serial.println("/");             // confirmation for parse finish
    wifi.println("AT+CIPCLOSE");     // at this point you should see "............/" in serial monitor (5 dots + /)
    delay(1000);
    Serial.println("");
    Serial.println("WEATHER PREVISION");
/*  Original working code
    Serial.print(day0); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high0); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low0); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop0); Serial.println("%");
    Serial.print(day1); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high1); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low1); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop1); Serial.println("%");
    Serial.print(day2); Serial.print(": ");
    Serial.print("High temp "); Serial.print(high2); Serial.print("\260C ");
    Serial.print(" Low temp: "); Serial.print(low2); Serial.print("\260C ");
    Serial.print(" Chance of rain "); Serial.print(pop2); Serial.println("%");
*/
    Serial.print("Today: "); Serial.println(text0);
    Serial.print("Tomorrow: "); Serial.println(text1);
    Serial.print("Next day: "); Serial.println(text2);

}


void parseForecastJSON(char json[400]) {
  StaticJsonBuffer<buffer> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(json);
  if (!root.success()) {
    Serial.println(F("parseObject() failed"));
    wifi.println(F("AT+CIPCLOSE"));
    delay(2000);
    updatePrevision();
  }

/* original working code
  day0   = root["day_0"];
  high0  = root["high_0"];
  low0   = root["low_0"];
  icono0 = root["icon_0"];
  pop0  = root["pop_0"];
  day1   = root["day_1"];
  high1  = root["high_1"];
  low1   = root["low_1"];
  icono1 = root["icon_1"];
  pop1  = root["pop_1"];
  day2   = root["day_2"];
  high2  = root["high_2"];
  low2   = root["low_2"];
  icono2 = root["icon_2"];
  pop2  = root["pop_2"];
*/

  text0   = root["text_0"];
  text1   = root["text_1"];
  text2   = root["text_2"];

}

And what I get on the serial monitor is this:

ESP8266 mode 1
WiFi full configured
Loop start

…parseObject() failed
…parseObject() failed
…parseObject() failed

I understand that the problem is somewhere in the parse, but I don´t know how to program it. I already had trouble finding the first code that works, and I don´t know how to program the one I need.
I hope these explanations help to clarify the problem and my situation. I wouldn´t like to throw away two months of hard work. Thank you.

Attached the sketches and the Wunderground response, for better reading.
Posted in various messages because of the 9000 char limit.

wunderground web.txt (7.95 KB)

fail_sketch.ino (7.68 KB)

working_sketch.ino (6.36 KB)

No one with a bit of free time can help me with this disaster, please?? :frowning: :frowning: