Climate temperature and rain API

Hello! I am looking for a simple API for weather forecasts, any suggestions? (also, I am a beginner!)

Thanks,
Isabela

Hi

4 Likes

Hello @isabela,

I was able to generate custom free APIs from this site:

Free Open-Source Weather API | Open-Meteo.com

Example for visibility and windspeed to get you started:

// Weather API JSON  
// By:   glv
// Date: 2023-5-20
// Ver:  1.0.0

// https://open-meteo.com/en/terms

// Weather data by Open-Meteo.com
// https://open-meteo.com/

JSONObject jsonObj;
JSONArray jsonArr;

String url = "https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=visibility,windspeed_10m&forecast_days=1";

void setup() 
  {
  size(300, 200);
  background(255);
 // https://open-meteo.com/en/terms
  println("Weather data by Open-Meteo.com");
  println("https://open-meteo.com/");
  println();
  
  jsonObj = loadJSONObject(url);
  println("*** jsonObj keys ***\n", jsonObj.keys());
  println();
  
  JSONObject hourly = jsonObj.getJSONObject("hourly");
  println("*** hourly keys ***\n", hourly.keys());
  println();
  
  println("*** hourly ***\n", hourly);
  println();
  
  println(hourly.getJSONArray("time").size());
  printArray(hourly.getJSONArray("time"));
  println();
 
 // https://open-meteo.com/en/terms
 textSize(16);
 fill(255, 0, 0);
 text("Weather data by Open-Meteo.com", 10, 20);
 text("https://open-meteo.com/", 10, 40);
 }
Console output < Click to expand!
Weather data by Open-Meteo.com
https://open-meteo.com/

*** jsonObj keys ***
[elevation, hourly_units, generationtime_ms, timezone_abbreviation, timezone, latitude, utc_offset_seconds, hourly, longitude]

*** hourly keys ***
[visibility, windspeed_10m, time]

*** hourly ***
{
 "visibility": [
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140,
   24140
 ],
 "windspeed_10m": [
   8.6,
   8.4,
   9.2,
   9.8,
   8.6,
   10.9,
   10.9,
   11.6,
   14.5,
   16.7,
   16.2,
   15.5,
   16.6,
   17,
   17.7,
   17,
   17.6,
   15.9,
   13.3,
   10.6,
   11.4,
   12,
   9.9,
   10.7
 ],
 "time": [
   "2023-05-20T00:00",
   "2023-05-20T01:00",
   "2023-05-20T02:00",
   "2023-05-20T03:00",
   "2023-05-20T04:00",
   "2023-05-20T05:00",
   "2023-05-20T06:00",
   "2023-05-20T07:00",
   "2023-05-20T08:00",
   "2023-05-20T09:00",
   "2023-05-20T10:00",
   "2023-05-20T11:00",
   "2023-05-20T12:00",
   "2023-05-20T13:00",
   "2023-05-20T14:00",
   "2023-05-20T15:00",
   "2023-05-20T16:00",
   "2023-05-20T17:00",
   "2023-05-20T18:00",
   "2023-05-20T19:00",
   "2023-05-20T20:00",
   "2023-05-20T21:00",
   "2023-05-20T22:00",
   "2023-05-20T23:00"
 ]
}

24
[
 "2023-05-20T00:00",
 "2023-05-20T01:00",
 "2023-05-20T02:00",
 "2023-05-20T03:00",
 "2023-05-20T04:00",
 "2023-05-20T05:00",
 "2023-05-20T06:00",
 "2023-05-20T07:00",
 "2023-05-20T08:00",
 "2023-05-20T09:00",
 "2023-05-20T10:00",
 "2023-05-20T11:00",
 "2023-05-20T12:00",
 "2023-05-20T13:00",
 "2023-05-20T14:00",
 "2023-05-20T15:00",
 "2023-05-20T16:00",
 "2023-05-20T17:00",
 "2023-05-20T18:00",
 "2023-05-20T19:00",
 "2023-05-20T20:00",
 "2023-05-20T21:00",
 "2023-05-20T22:00",
 "2023-05-20T23:00"
]

Resources:

There is a learning curve to all of this and it will take time… take it in steps.

Once you can access and retrieve the data then you can visualize it with additional code.

There rest is up to you and your creativity and imagination!

image

:)

3 Likes

Mind telling us a bit more about the sketch you’d like to create? Happy to help and am curious to know whether you’d like data for a specific location, an entire region, or something else.

1 Like

Thanks, that helped a lot! :smiley:
I was able to run a program with a Brazilian API (where I am from) but I don’t know how I can transform the “printlin” information in graphics on the program (let me know if I made myself clear…)
Can you help me with that?

You will first have to extract the data from the JSONArray of interest.

This will extra one of the data elements:

Once you are able to extract the data you can then plot the data or visualize it any way you want.

Try extracting the data in a for loop and plotting points on the screen.

The time may be a challenge but a little research will sort that out.

:)