Weather API

As we mentioned earlier, apart from temperature and humidity, we will measure wind speed, atmospheric pressure, and sunrise and sunset times using free and open source weather APIs.

Quite a few weather APIs are available for free. We will use the OpenWeatherMap API, which is easy to use and requires just a simple registration on their website to get started. It provides a REST-based API endpoint to get the weather data in JSON format. As input parameters, we need to provide a city ID, which is provided on the website itself, and APPID, which you will get after registration.

Let's go through the registration process and see how it works:

  1. Log on to http://www.openweathermap.com/ and click on Sign Up.
  2. A registration page will appear; provide your username, email, and password to complete the registration.
  1. Once successfully logged in to your account, the following page will appear:
  1. Select the API keys tab to get your key, which will be used in the API call:
  1. To get the IDs of your city and state, download the list (city.list.json.gz) from this link: http://bulk.openweathermap.org/sample/.
  2. A brief description has been given on how to API endpoints at link: https://openweathermap.org/appid.
  3. Try to get current weather data using the city ID and App key. We will use Postman as the API tool. You can use any API tool of your choice.
  1. A HTTP Get request is sent along with city id and APPID (key), shown as follows:
  • Request:
  • Response:

In response, we get a long list of information but we will use wind speed, atmospheric pressure, and sunset and sunrise times. You can use other information as well if you want.

In our project, we will use this API endpoint programmatically in our code without using Postman.

Since we covered Raspberry Pi in depth in Chapter 2, Know Your Raspberry Pi, we are not going to cover it again here.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.228.95