Welcome to the lesson on reading weather data in Raspberry Pi using Openweathermap API.
So from Openweathermap API, we can read weather data like temperature, humidity, rain, cloud information.
So I'll be showing you how we can read this data into Raspberry Pi.
So we are going to read this data by using Http protocol history.
Http is hypertext transfer protocol.
It works in a client server model.
Our Raspberry Pi works as a Http client, whereas Openweathermap is a Http server from Raspberry Pi.
We will make a request to the Openweathermap server for this weather data like temperature, humidity
and rain.
Once we receive this data from Openweathermap into Raspberry Pi, we will parse the data and then we
will separate.
Temperature, humidity and other, you know, related information.
So we are going to use Http protocol in Python.
We have request module.
This request module is very helpful for making http get request or post request.
I'll be showing you how we can make Http get request in Python programming.
Now log in to Raspberry Pi.
Now go to Linux terminal.
Now we will try retrieving data.
In the python shell open python.
So type python.
Now we are in the Python command prompt.
Now we will try to write commands in this python shell.
The first step is import requests.
Now done with the importing request.
Once you import the request, the next step is create the URL variable.
So already we tested this URL.
So copy this URL.
Copy this URL.
Create a variable.
So this is the URL variable.
And now the next step, all of you print URL.
Now you can make requests to this URL http request to this URL.
So request dot get.
URL.
So once you make the request, you will get the response.
We have to store the response.
So to store the response, take a variable R, So R is the response object.
So we are storing the response in R.
Now print our.
Once you print out, you can see response 200.
This means we made a successful request and we got the response from the Openweathermap server so we
can see the response.
So to check the response type r dot text.
So this will print the response in string format.
Now we can see the response in string format.
So we can see this Json response like coordinates, weather information and also, uh, temperature
main temperature fields like temperature, temperature, minimum temperature, maximum pressure, humidity,
visibility, wind speed, so on.
So we can see this data here, right?
So if you want to convert this into Python dictionary, you can use a method or Json.
So let us take another variable.
S s is equal to r dot Json.
Now you can check the type of S type of s.
It is a dictionary, right?
So you can print this dictionary.
Print.
Yes.
Now, this is the response.
We can see the response in Python dictionary format.