Openweather NANO 33 IOT call issue

Dear Forum,

I am trying to collect weather data from openweather.com on a NANO33 IOT (and JSON 6.X). I have registered to the Free plan what gives access to current and forecast weather data (with some calls/minute limitation).
The current weather call works as expected in browser and on IOT:

WEB: https://api.openweathermap.org/data/2.5/weather?q=Kecskemét,HU&units=metric&lang=en&appid=8011c12baf06f1039a90b90f94af4199

code: Api Actual

However changing the parameters following website instructions the forecast call works in browser but on NANO IOT "serialprint"-ing ApiData returns nothing

WEB: https://api.openweathermap.org/data/2.5/onecall?lat=46.90&lon=19.69&exclude=minutely,alerts,daily&units=metric&lang=en&appid=8011c12baf06f1039a90b90f94af4199

code: API forecast

(The API key seen at the end of browser link works for one week, use it in the code)

Could somebody tell me what I am doing in a wrong way?
Many thanks in advance.

Best,
Szabolcs

I use the following on an ESP32 to retrieve the weather data.


String httpGETRequest(const char* fullURL) {
  String payload = "{}";
  WiFiClient client;
  HTTPClient http;

  http.begin(client, fullURL);
  int httpResponseCode = http.GET();
  if (httpResponseCode == 200) {
    payload = http.getString();
  } else {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
  }
  http.end();
  return payload;
}
1 Like

Hi Whandal,

Thanks for the reply. The data is retrieved in HTML format or JSON? I assume in HTML. I am looking for JSON.
For me still an open question how is it possible that the code for "current weather" call works but "forecast" does not. I have double checked all the attributes I even tested in Postman.

Thanks.

Szabolcs

You assume wrong, I retrieve JSON from the onecall interface

OneCall

      String serverPath = "http://api.openweathermap.org/data/2.5/onecall?lat=" + mLat + "&lon=" + mLon + "&exclude=minutely,hourly&lang=de&appid=" + owmKey;  //

      weatherJSONText = httpGETRequest(serverPath.c_str());
      weatherJSONObj = JSON.parse(weatherJSONText);

      if (JSON.typeof(weatherJSONObj) == "undefined") {
        Serial.println("Parsing input failed!");
        return;
      }
      if (emitFullJSON) {
        //Serial.print("JSON object = ");
        Serial.println(weatherJSONObj);
      }
      printWeatherJSON();

But it would not matter anyway, because the function returns the whole reply.

Hi Whandall,

Thanks for your help. I was playing a bit with my code and I think I have found the issue
but now gets more interesting. It looks like if I call only "hourly" data than serialprint does not show any data ("&exclude=minutely,current,alerts,daily).
As I see in your code you excluded "hourly". Could you please try it on your your end what happens?
If you can retrieve the hourly forecast than maybe the NANO33 IOT board has not enough memory? Arduino JSON Assistant suggests 24576 byte need to store that data.

(Probably you noticed I am not an expert just a hobbyist so any of your help is appreciated!)

Thanks,
Szabolcs

I tried

String serverPath = "http://api.openweathermap.org/data/2.5/onecall?lat=" + mLat + "&lon=" + mLon + "&exclude=minutely&lang=de&appid=" + owmKey;

and got for the size of the JSON String

Size of answer is 18035.

While the same request with excluded hourly gives

Size of answer is 4585.

Hi,

Many thanks for your help. It looks like Nano33 IOT has not enough memory to handle the size of the JSON String.
I appreciate your help.

Best,
Szabolcs

I use an ESP32 for my weather display

e-paper is perfect for a weather display IMHO.

Their application is also quite nice, the only thing I'm missing is the times of Moon rise and set.

1 Like

Hi, many thanks. The original project is a garden watering system and I alternate the daily programs with sunset/sundown and current weather data. When I was playing with API came the idea to poll weather forecast data to show it on the TFT.
Now my ESP is on the way, it will do the forecast poll. I will wiretransfer (IIC) it to the NANO to visualize it on the TFT.
So again many thanks for your help. If you are interested I can share the whole project with you when I am finished.