How to do it...

Let's follow the steps required in this recipe:

  1. Run the following lines of code in the REPL:
>>> import urequests >>> >>> API_URL = 'http://api.openweathermap.org/data/2.5/weather' >>> 
  1. The API_URL variable has now been defined, which we will use to access the weather API. In the next block of code, we define APPID and city to get weather data for. Make sure to replace the APPID value with your actual APPID value. We will now build the URL by combining these variables, which we we can then access:
>>> APPID = 'put-your-API-key(APPID)-here'
>>> city = 'Berlin'
>>> url = API_URL + '?units=metric&APPID=' + APPID + '&q=' + city
  1. The following block of code will connect to the weather API and retrieve the weather data:
>>> ...

Get MicroPython Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.