Comments on: ESP8266 Weather Forecaster https://randomnerdtutorials.com/esp8266-weather-forecaster/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Tue, 26 Aug 2025 10:30:52 +0000 hourly 1 https://wordpress.org/?v=6.8.5 By: Sara Santos https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-1086501 Tue, 26 Aug 2025 10:30:52 +0000 http://randomnerdtutorials.com/?p=43469#comment-1086501 In reply to David (:acodemonkey:).

Hi.
Thanks for the update.
This tutorial has not been updated for quite some time.
But, it should work with previous versions of the libraries.
Regards,
Sara

]]>
By: David (:acodemonkey:) https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-1086334 Tue, 26 Aug 2025 02:44:56 +0000 http://randomnerdtutorials.com/?p=43469#comment-1086334 Hallo Emmanuel, Sara and Rui
That’s great work, once again!
Thank you very much for your efforts over the years, now I can contribute something too :).

I noticed that the code in this example is a little outdated and I think it’s far too difficult for beginners to understand the errors or even adapt the code.

But first, another minor issue: the sketch often got stuck in the while(client.available()){} loop.

while (client.available()) { // ~line 117
delay(1); // ~line 118 brought more stability
c = client.read();
.
.
.

The code only runs error-free with ArduinoJson 5. Adapting it for ArduinoJson version 7 wasn’t that difficult.

For those who get the following error:
DynamicJsonBuffer is a class from ArduinoJson 5. Please see https://arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 7

You only need to change some lines in this function void parseJson(const char * jsonString), arround line 151. Perhaps you can copy and paste the following function in your code.

//to parse json data recieved from OWM
void parseJson(const char * jsonString) {

// deprecated code ——————————————————————
/*
//StaticJsonBuffer jsonBuffer;
const size_t bufferSize = 2JSON_ARRAY_SIZE(1) + JSON_ARRAY_SIZE(2) + 4JSON_OBJECT_SIZE(1) + 3JSON_OBJECT_SIZE(2) + 3JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + 2JSON_OBJECT_SIZE(7) + 2JSON_OBJECT_SIZE(8) + 720;
DynamicJsonBuffer jsonBuffer(bufferSize);

// FIND FIELDS IN JSON TREE
JsonObject& root = jsonBuffer.parseObject(jsonString);
if (!root.success()) {
Serial.println(“parseObject() failed”);
return;
}

JsonArray& list = root[“list”];
JsonObject& nowT = list[0];
JsonObject& later = list[1];
*/
// deprecated code end ——————————————————————————–

// New Code ————————————————————————————————-
JsonDocument root;

DeserializationError error = deserializeJson(root, jsonString);
if (error) {
Serial.println(“deserializeJson() returned “+ String(error.c_str()));
return;
}

JsonArray list = root[“list”];
JsonObject nowT = list[0];
JsonObject later = list[1];

// New Code End —————————————————————————————–

// including temperature and humidity for those who may wish to hack it in

String city = root[“city”][“name”];

long sunrise = root[“city”][“sunrise”];
long sunset = root[“city”][“sunset”];

float tempNow = nowT[“main”][“temp”];
float humidityNow = nowT[“main”][“humidity”];
String weatherNow = nowT[“weather”][0][“description”];

float tempLater = later[“main”][“temp”];
float humidityLater = later[“main”][“humidity”];
String weatherLater = later[“weather”][0][“description”];

// checking for four main weather possibilities
diffDataAction(weatherNow, weatherLater, “clear”);
diffDataAction(weatherNow, weatherLater, “rain”);
diffDataAction(weatherNow, weatherLater, “snow”);
diffDataAction(weatherNow, weatherLater, “hail”);

Serial.println();
}

]]>
By: Hans harbeck https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-952872 Sat, 31 Aug 2024 15:40:13 +0000 http://randomnerdtutorials.com/?p=43469#comment-952872 This did work for me a long time.
But since a month or two it only says “Connecting to server” and no more.
What must I do?

]]>
By: Ed https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-874541 Mon, 27 Nov 2023 13:55:14 +0000 http://randomnerdtutorials.com/?p=43469#comment-874541 I know this is already an old post, but I stumbled upon it as I needed a quick API call to OWM. As stated in one of the comments, this code could be a bit simpler with rtegard to the http request as well as with the json parser.
Foolish as I am, I first tried ‘converting’ the code to ArduinoJson6, but decided it would be simpler to just start from scratch.
It is a quick and simple (quick and dirty) code that pulls the items I need and that works with ArduinoJson version 6. Though I do not need it, I added the ‘weather id” that the code in this article relies upon to light op the LED’s. So if that is all one needs, it is simple to add the LEDs in the program.
The http request in my program uses London, GB as place to sample, so when using it one would need to change it to another location, also one needs to add one’s own apiKey as well as SSID and PW.
Location and apikey all need to be put directly in the request url. I did not bother to build it from variables as I was in a hurry…and do not need it.
The program can be found here: https://gitlab.com/diy_bloke/openweathermap/

]]>
By: Ed https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-874528 Mon, 27 Nov 2023 12:24:20 +0000 http://randomnerdtutorials.com/?p=43469#comment-874528 For those having problems with converting to JSON6. There is an assistent that can generate the right code for you:
https://arduinojson.org/v6/assistant/#/step1

]]>
By: Ed https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-874392 Sun, 26 Nov 2023 18:09:24 +0000 http://randomnerdtutorials.com/?p=43469#comment-874392 In reply to Michael Shu.

Michael,
Given that you gave your reply in 2019, I guess that is still for the ArduinJson version 5 library.
I think that for the ArduinoJson library, the entite parse section can be replaced by the following:

DynamicJsonDocument jsonDocument(capacity);
// Parse JSON
DeserializationError error = deserializeJson(jsonDocument, json);

// Check for parsing errors
if (error) {
Serial.print(“Error parsing JSON: “);
Serial.println(error.c_str());
return;
}

// Access the “id” value within the first element of the “weather” array

int list_1_weather_0_id = jsonDocument[“list”][0][“weather”][0][“id”];

I think the reading of the JSON can be simplified too (as was suggested before) by
c=client.readStringUntil(ā€˜\n’);
but I have not tried that

]]>
By: Sara Santos https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-802929 Tue, 13 Dec 2022 20:13:45 +0000 http://randomnerdtutorials.com/?p=43469#comment-802929 In reply to Steven Elves.

Please make sure you have version 5 of the ArduinoJson library so that it is compatible with this code.
Regards,
Sara

]]>
By: Steven Elves https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-802119 Sun, 11 Dec 2022 06:19:02 +0000 http://randomnerdtutorials.com/?p=43469#comment-802119 I get the following message:

DynamicJsonBuffer is a class from ArduinoJson 5. Please see https://arduinojson.org/upgrade to learn how to upgrade your program to ArduinoJson version 6

Can you advise how to fix this? The link they provide is not particularly helpful.

Thank you.

]]>
By: Ted https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-649190 Tue, 20 Jul 2021 21:42:31 +0000 http://randomnerdtutorials.com/?p=43469#comment-649190 In reply to Ethan Tabler.

Thanks, Ethan. Two years later and it still works great!

]]>
By: Ruben Cretegny https://randomnerdtutorials.com/esp8266-weather-forecaster/#comment-614252 Tue, 25 May 2021 17:53:39 +0000 http://randomnerdtutorials.com/?p=43469#comment-614252 In reply to ULi.

Hello ULi,
You made my day ! Thank you
Ruben

]]>