# I have ported a remote weather app to Picoexplorer

**URL:** <https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330>\
**Category:** Discussion\
**Created:** [November 22, 2023, 1:58pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330 "2023-11-22T13:58:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 22, 2023, 1:58pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/1 "2023-11-22T13:58:14Z")

</div>

Uses latest firmware from Pinorami  
MicroPython v1.21.0, picow v1.21.0 on 2023-10-06; Raspberry Pi Pico W with RP2040

you may have to set up your own api at open weather and put in your location at line 21

import network  
import time  
import secrets  
import urequests

from picographics import PicoGraphics, DISPLAY\_PICO\_EXPLORER

# WIDTH, HEIGHT = display.get\_bounds()

# set up the hardware

display = PicoGraphics(display=DISPLAY\_PICO\_EXPLORER)  
WHITE = display.create\_pen(255, 255, 255)

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?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial](https://api.openweathermap.org/data/2.5/weather?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial)”).json()  
weather=urequests.get(“[https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial](https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&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’)  
myTime=time.time()  
while True:  
if time.time()-myTime\>300:  
weather=urequests.get(“[https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=098014b8c21bddb718496a654f417674&units=imperial](https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=098014b8c21bddb718496a654f417674&units=imperial)”).json()  
tm=time.localtime(weather[‘dt’]+weather[‘timezone’])  
ss=time.localtime(weather[‘sys’][‘sunset’]+weather[‘timezone’])  
myTime=time.time()  
print(‘New Data Read’)  
display.set\_pen(WHITE)

```
display.text('Welcome '+weather['name'],0,0)
sr=time.localtime(weather['sys']['sunrise']+weather['timezone'])
display.set_pen(WHITE) 

display.text('Time: '+str(tm[3])+':'+str(tm[4]),0,16)
display.text('Date: '+str(tm[1])+'/'+str(tm[2])+'/'+str(tm[0]),0,32)
display.text('Sunrise: '+str(sr[3])+':'+str(sr[4]),0,48)
display.text('Sunset: '+str(ss[3]-12)+':'+str(ss[4])+' PM',0,64)
display.update()
time.sleep(10)
display.set_pen(WHITE) 
#display.text('Welcome to '+weather['name'],0,82)
display.text('Weather: ',0,82)
display.text('Temp: '+str(weather['main']['temp'])+' F',0,94)
display.text('Humidity: '+str(weather['main']['humidity'])+' %',0,110)
display.text('BP: '+str(weather['main']['pressure']*0.0009869233)+' ATM',0,126)
display.text('Wind: '+str(weather['wind']['speed'])+' MPH',0,142)
display.update()
time.sleep(5)
#dsp.fill(0)
WHITE = display.create_pen(255, 255, 255)
display.set_pen(WHITE)
#display.text('Welcome to '+weather['name'],0,178)
display.text('Conditions: ',0,160)
row=26
for i in range(len(weather['weather'])):
    display.text(weather['weather'][i]['main'],0,176)
    row=row+10
    display.text(weather['weather'][i]['description'],0,192)
    row=row+10
display.update()
time.sleep(5)

#dsp.fill(0)

```

---

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 22, 2023, 2:04pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/2 "2023-11-22T14:04:45Z")

</div>

sorry about code layout dont know how to attach file

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [November 22, 2023, 6:55pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/3 "2023-11-22T18:55:09Z")

</div>

Click the Preformatted Text button, the **\</\>**.  
The other way to do it is three ` at the top of your block of code, and three more at the end / bottom.

---

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 23, 2023, 4:00pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/4 "2023-11-23T16:00:43Z")

</div>

‘’’  
import network  
import time  
import secrets  
import urequests

from picographics import PicoGraphics, DISPLAY\_PICO\_EXPLORER

# WIDTH, HEIGHT = display.get\_bounds()

# set up the hardware

display = PicoGraphics(display=DISPLAY\_PICO\_EXPLORER)  
WHITE = display.create\_pen(255, 255, 255)

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?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial](https://api.openweathermap.org/data/2.5/weather?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial)”).json()  
weather=urequests.get(“[https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial](https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&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’)  
myTime=time.time()  
while True:  
if time.time()-myTime\>300:  
weather=urequests.get(“[https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial](https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial)”).json()  
tm=time.localtime(weather[‘dt’]+weather[‘timezone’])  
ss=time.localtime(weather[‘sys’][‘sunset’]+weather[‘timezone’])  
myTime=time.time()  
print(‘New Data Read’)  
display.set\_pen(WHITE)

```
display.text('Welcome '+weather['name'],0,0,300,3)
sr=time.localtime(weather['sys']['sunrise']+weather['timezone'])
display.set_pen(WHITE) 

display.text('Time: '+str(tm[3])+':'+str(tm[4]),0,18,)
display.text('Date: '+str(tm[1])+'/'+str(tm[2])+'/'+str(tm[0]),0,33)
display.text('Sunrise: '+str(sr[3])+':'+str(sr[4]),0,46)
display.text('Sunset: '+str(ss[3]-12)+':'+str(ss[4])+' PM',0,64)
display.update()
#time.sleep(10)
display.set_pen(WHITE) 
#display.text('Welcome to '+weather['name'],0,82)
display.text('Weather: ',0,82)
display.text('Temp: '+str(weather['main']['temp'])+' F',0,96)
display.text('Humidity: '+str(weather['main']['humidity'])+' %',0,112)
display.text('BP: '+str(weather['main']['pressure']*0.0009869233)+' ATM',0,128)
display.text('Wind: '+str(weather['wind']['speed'])+' MPH',0,144)
display.update()
#time.sleep(5)
#dsp.fill(0)
WHITE = display.create_pen(255, 255, 255)
display.set_pen(WHITE)
#display.#text('Welcome to '+weather['name'],0,178)
display.text('Conditions: ',0,160)
row=26
for i in range(len(weather['weather'])):
    display.text(weather['weather'][i]['main'],0,176)
    row=row+10
    display.text(weather['weather'][i]['description'],0,192)
    row=row+10
display.update()
#time.sleep(5)

```

‘’’

---

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 23, 2023, 4:08pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/5 "2023-11-23T16:08:11Z")

</div>

```auto
'''
import network
import time
import secrets
import urequests
 

from picographics import PicoGraphics, DISPLAY_PICO_EXPLORER
# WIDTH, HEIGHT = display.get_bounds()
# set up the hardware
display = PicoGraphics(display=DISPLAY_PICO_EXPLORER)
WHITE = display.create_pen(255, 255, 255) 

 
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?lat=0.478623&lon=33.164364&appid=0d631313b55e6e128285fd7882ba913f&units=imperial").json()
weather=urequests.get("https://api.openweathermap.org/data/2.5/weather?q=glasgow&appid=6b72756ad1ab174cd04a01ce9b1b3430&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')
myTime=time.time()
while True:
    if time.time()-myTime>300:
       weather=urequests.get("https://api.openweathermap.org/data/2.5/weather?q=Jinja,Uganda&appid=6b72756ad1ab174cd04a01ce9b1b3430&units=imperial").json()
       tm=time.localtime(weather['dt']+weather['timezone'])
       ss=time.localtime(weather['sys']['sunset']+weather['timezone'])
       myTime=time.time()
       print('New Data Read')
    display.set_pen(WHITE) 
    
    display.text('Welcome '+weather['name'],0,0,300,3)
    sr=time.localtime(weather['sys']['sunrise']+weather['timezone'])
    display.set_pen(WHITE) 

    display.text('Time: '+str(tm[3])+':'+str(tm[4]),0,18,)
    display.text('Date: '+str(tm[1])+'/'+str(tm[2])+'/'+str(tm[0]),0,33)
    display.text('Sunrise: '+str(sr[3])+':'+str(sr[4]),0,46)
    display.text('Sunset: '+str(ss[3]-12)+':'+str(ss[4])+' PM',0,64)
    display.update()
    #time.sleep(10)
    display.set_pen(WHITE) 
    #display.text('Welcome to '+weather['name'],0,82)
    display.text('Weather: ',0,82)
    display.text('Temp: '+str(weather['main']['temp'])+' F',0,96)
    display.text('Humidity: '+str(weather['main']['humidity'])+' %',0,112)
    display.text('BP: '+str(weather['main']['pressure']*0.0009869233)+' ATM',0,128)
    display.text('Wind: '+str(weather['wind']['speed'])+' MPH',0,144)
    display.update()
    #time.sleep(5)
    #dsp.fill(0)
    WHITE = display.create_pen(255, 255, 255)
    display.set_pen(WHITE)
    #display.#text('Welcome to '+weather['name'],0,178)
    display.text('Conditions: ',0,160)
    row=26
    for i in range(len(weather['weather'])):
        display.text(weather['weather'][i]['main'],0,176)
        row=row+10
        display.text(weather['weather'][i]['description'],0,192)
        row=row+10
    display.update()
    #time.sleep(5)
   ''' 
    

```

---

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 23, 2023, 4:09pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/6 "2023-11-23T16:09:54Z")

</div>

I would like the weather app update every 10 mins

how can i do this

thanks

r

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [November 23, 2023, 4:14pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/7 "2023-11-23T16:14:45Z")

</div>

The ` is on the key next to the 1 key. It also has the ~ on it. On an English keyboard anyway.

---

<div class="post-metadata">

**Author:** ![Tonygo2](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/tonygo2/32/7814_2.png) [@Tonygo2](https://forums.pimoroni.com/u/Tonygo2)\
**Post date:** [November 24, 2023, 7:28pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/8 "2023-11-24T19:28:36Z")

</div>

I’ve got a UK Pi Keyboard and the ’ is below the @ and the ~ is above the #.

---

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [November 24, 2023, 7:40pm UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/9 "2023-11-24T19:40:05Z")

</div>

The easiest way is to click the Preformatted Text option, \</\>.

---

<div class="post-metadata">

**Author:** ![rfairman](https://avatars.discourse-cdn.com/v4/letter/r/85e7bf/32.png) [@rfairman](https://forums.pimoroni.com/u/rfairman)\
**Post date:** [November 25, 2023, 10:27am UTC](https://forums.pimoroni.com/t/i-have-ported-a-remote-weather-app-to-picoexplorer/23330/10 "2023-11-25T10:27:45Z")

</div>

modified the picoexplorer weather app so it can send weather alerts via sms, whatsapp or email.

r
