In this video lesson we show you step-by-step instructions on how to build a sensorless weather station on your Raspberry Pi Pico W. We show how to download real-time weather data from the internet, how to parse the data, and then display it. For your convenience, we include the code below which we develop in the video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import network import time import secrets import urequests wlan=network.WLAN(network.STA_IF) wlan.active(True) wlan.connect(secrets.SSID,secrets.PASSWORD) while wlan.isconnected()==False: print('Connecting . . .') print('Congratulations, You Have Connected') weather=urequests.get("https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=0d631313b55e6e128285fd7882ba913f&units=imperial").json() tm=time.localtime(weather['dt']+weather['timezone']) print('Welcome to '+weather['name']+', '+weather['sys']['country']) print('Local Time: '+str(tm[3])+':'+str(tm[4])+' '+str(tm[1])+'/'+str(tm[2])+'/'+str(tm[0])) sr=time.localtime(weather['sys']['sunrise']+weather['timezone']) print('Sunrise at: '+str(sr[3])+':'+str(sr[4])) ss=time.localtime(weather['sys']['sunset']+weather['timezone']) print('Sunset at: '+str(ss[3]-12)+':'+str(ss[4])+' PM') print('Current Temp: '+str(weather['main']['temp'])+' F') print('Current Humidity: '+str(weather['main']['humidity'])+' %') print('Current Barometric Pressure: '+str(weather['main']['pressure']*0.0009869233)+' ATM') for i in range(len(weather['weather'])): print('Current Conditions: '+weather['weather'][i]['main']+', '+weather['weather'][i]['description']) print('Wind: '+str(weather['wind']['speed'])+' MPH') |