In this example, we will understand how to use HTTP requests to get weather data from OpenWeatherMap API.
OpenWeatherMap Account
Create the account with the following method:
- Click on Create an Account on the website: https://openweathermap.org/
- Fill in the signup details.
- Click on Create Account.
- Fill the in the details about usage.
- Go to API and copy the API for further usage.
API Request
The following is the method provided by OpenWeatherMaps for fetching the weather data using the lat and longitude of the location.
On making the HTTP Request, we get the following data:
{
"coord": {
"lon": 77.4977,
"lat": 27.2046
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 304.66,
"feels_like": 303.14,
"temp_min": 304.66,
"temp_max": 304.66,
"pressure": 1012,
"humidity": 27,
"sea_level": 1012,
"grnd_level": 992
},
"visibility": 10000,
"wind": {
"speed": 1.09,
"deg": 3,
"gust": 1.17
},
"clouds": {
"all": 0
},
"dt": 1666781571,
"sys": {
"country": "IN",
"sunrise": 1666745753,
"sunset": 1666786313
},
"timezone": 19800,
"id": 1276128,
"name": "Bharatpur",
"cod": 200
}
The data is in JSON format, which we can use in PictoBlox.
PictoBlox Script
The following script makes the HTTP request and makes the Tobi say the temperature of the location.