Arduino_JSON works on my Nodemcu 32-s but not on my nodemcu 1.0 ESP-12e

Hello,
I have made a klok with some weather animations using a Nodemcu 32-s ... everything works great. Now I want to get some weather animations on my older klok which uses a nodemcu 1.0 ESP-12e but getting the 'icon' code from the JSON object gives the error ;
ambiguous overload for 'operator=' (operand types are 'String' and 'JSONVar')

I not really good with the whole coding thing, mostly copy and paste and try to understand and modify a bit. But I don`t know why the sketch works on one (nodemcu32-s) and not the other(nodemcu1.0 esp12e).

/*
  Rui Santos
  Complete project details at Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-http-get-open-weather-map-thingspeak-arduino/

  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

  Code compatible with ESP8266 Boards Version 3.0.0 or above 
  (see in Tools > Boards > Boards Manager > ESP8266)
*/
//#include <WiFi.h>    //  (Nodemcu 32-s)  works well
#include <ESP8266WiFi.h>   // (nodemcu 1.0 ESP-12e)
//#include <HTTPClient.h>  //  (Nodemcu 32-s) works well 
#include <ESP8266HTTPClient.h> //   (nodemcu 1.0 ESP-12e)
#include <WiFiClient.h>
#include <Arduino_JSON.h>

const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Your Domain name with URL path or IP address with path
String openWeatherMapApiKey = "REPLACE_WITH_YOUR_OPEN_WEATHER_MAP_API_KEY";
// Example:
//String openWeatherMapApiKey = "bd939aa3d23ff33d3c8f5dd1dd4";

// Replace with your country code and city
String city = "Porto";
String countryCode = "PT";
String icon;

// THE DEFAULT TIMER IS SET TO 10 SECONDS FOR TESTING PURPOSES
// For a final application, check the API call limits per hour/minute to avoid getting blocked/banned
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 10 seconds (10000)
unsigned long timerDelay = 10000;

String jsonBuffer;

void setup() {
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("Timer set to 10 seconds (timerDelay variable), it will take 10 seconds before publishing the first reading.");
}

void loop() {
  // Send an HTTP GET request
  if ((millis() - lastTime) > timerDelay) {
    // Check WiFi connection status
    if(WiFi.status()== WL_CONNECTED){
      String serverPath = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + countryCode + "&APPID=" + openWeatherMapApiKey;
      
      jsonBuffer = httpGETRequest(serverPath.c_str());
      Serial.println(jsonBuffer);
      JSONVar myObject = JSON.parse(jsonBuffer);
  
      // JSON.typeof(jsonVar) can be used to get the type of the var
      if (JSON.typeof(myObject) == "undefined") {
        Serial.println("Parsing input failed!");
        return;
      }
    
      Serial.print("JSON object = ");
      Serial.println(myObject);
      icon = (myObject["weather"][0]["icon"]);  // gives error on the nodemcu1.0 esp12e 
      Serial.print("Temperature: ");
      Serial.println(myObject["main"]["temp"]);
      Serial.print("Pressure: ");
      Serial.println(myObject["main"]["pressure"]);
      Serial.print("Humidity: ");
      Serial.println(myObject["main"]["humidity"]);
      Serial.print("Wind Speed: ");
      Serial.println(myObject["wind"]["speed"]);
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    lastTime = millis();
  }
}

String httpGETRequest(const char* serverName) {
  WiFiClient client;
  HTTPClient http;
    
  // Your IP address with path or Domain name with URL path 
  http.begin(client, serverName);
  
  // Send HTTP POST request
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();

  return payload;
}

On my machine the code compiles without an error (I only get a warning). So I must guess you're compiling with outdated packages. Also keep in mind that the Arduino_JSON library is still in beta state (at least the version available in the library manager).

Okè, thx for looking at it... But if my packages are outdated why does it compile on the
Nodemcu 32-s without an error ??

And how can I update the correct packages ??
sry for silly question

I have no clue as I have no clue which exact version you're using and where exactly you got the error.

In the IDE Tools->Manage Libraries update the Arduino_JSON library (i assume you installed it there, otherwise you failed to post the link where you got the library). The update the core: Tools->Board->Boards Manager and update the ESP8266 core.
Compile again, you shouldn't get an error anymore.

1 Like

Well I tried that but both are updated, the libray and the esp8266 core.
Where I got the error is noted in the sketch icon = (myObj.......)
What vesion are you using for Arduino_JSON library and ESP8266 core ?
Mayby I should downgrade .... :face_with_raised_eyebrow:

It might be time to use ArduinoJson V6. The "Assistant" will write most of the code for you, given an example of the JSON document being parsed.

Wel, I got it to work ... just downgraded the esp8266 core to version 2.7.4. And now i compiles just fine and gives me the icon data I need.
Like I said I dont know quite what Im doing but thx. for pointing me in the right way ....
:+1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.