Video 4.2 using a web API. In this video, we will be building the same weather station using a web API called Dark Sky dotnet. You may already know there is a dark sky dotnet node present in the palette already. But now, we're going to try out the API. But why dark sky? Well, it actually provides a lot of data compared to other API's.
You can try out other API's also. Let's have a look at the website. We need to go to the API part. You have to register here. I have already registered. After you're done with the male authentication part and once you log in, you will get your secret key, which is nothing but the API key.
You can check the plan type here By default, you will get a trial account in which you can maximum make 1000 calls per day. You can also check your usage below. They have also given a sample API call. Since this is not sufficient, let's check out the documents. As you can see, there are two types of API request, forecast and time machine. We'll try both of them.
First forecast request, we have to call this URL using the get method like shown here. Let's do that first. Now let's see what else is there. Request parameters. It seems there are three required ones and many optional parameters. And they've mentioned that the optional ones can be added As query parameters, okay, let's do that.
I'm going to add language and units. Ta is for Tamil my local language, you can add yours. Then make sure you mentioned the return type as parsed JSON object. Let's deploy. We'll check the payload. As you can see, you are getting current hourly data for this day and daily data for the next week.
Isn't that cool? Since I gave units is equal to Si, I have got my data in SI unit and summary in my local language. Nice. Note that if you don't understand the response, you can go check out the response Format tab under Doc's Now I want you to pause the video and try to display the current weather data alone in a table on a web page with URL slash weather. If you don't know HTML, I have included link in the resources, which you can go through before proceeding further. Okay, pause here.
Did you build your own web page? Well, I have built mine. If you haven't built one, you can import my flow, which I've included in the resources to see how to build one. I have also explained the code with comments, so you will have no problem in understanding them. Finally, your weather station should look something like this. Good.
And to get the current data you have to refresh the page. Now let's try the Time Machine request. calling this API returns the observed or forecasted hour by hour weather and daily weather conditions for a particular date. Okay, let's have a look at the request parameters. Everything is the same, except we need to add the date and time for which we want to forecast. They have mentioned here about how to add the timezone format.
Add it in this format. This format is called ISO 8601 format. You can check it out in the resources. Now let's see if it works. Okay, it works. Now another task for you.
Since we have to send a time and date info here, I want you to use the dashboard, text input and date picker nodes and get the date and time from there, format it and send it with the URL. You can also send latitude and longitude values from the dashboard. Once you enter those values, you must be redirected to the slash weather link to show the weather data. Pause the video here and try it out. Did you try? How did it go?
I have included my flow in the resources for you to understand how I did it. Once everything is done, this is how it looks awesome, right. That is the end of this video. In this video, we learned how to get data from a web API and build a weather station. In the next video, we'll be using hardware. Be prepared with your Raspberry Pi because we will be using it to build a weather station.