Pimoroni Presto Feedback

The way to go is to skip NTP and use worldtimeapi.org. It returns a simple json-structure with all you need to extract your local time. And usually, it also does automatic geo-ip lookup. But you could pass your timezone explicitly.

You can write code that works all over the world and even with daylight summer time and things like that.

Since you have released the Presto as a Beta version I am hoping there is still room for hardware improvements.

Please include a debug header, so one can use the Raspberry Pi Debug Probe to program and debug the hardware. This debug header is included in some versions of the Pico 1 as well as the Pico 2. (Raspberry Pi 3-pin Debug Connector Specification).

Just tried worldtimeapi.org and just get errors.

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
Connected to Wi-Fi network.
('192.168.0.79', '255.255.255.0', '192.168.0.1', '194.168.4.100')
Traceback (most recent call last):
  File "<stdin>", line 96, in <module>
  File "requests/__init__.py", line 201, in get
  File "requests/__init__.py", line 151, in request
ValueError: HTTP error: BadStatusLine:
[]
>>>

Here is the code:

import time
from presto import Presto
import network
import rp2
import requests
rp2.country("GB")
from secrets import WIFI_SSID, WIFI_PASSWORD

# Setup for the Presto display
presto = Presto(full_res=True)
display = presto.display

WIDTH, HEIGHT = display.get_bounds()

touch = presto.touch # Activate touch

# Create some colours
BLUE = display.create_pen(20,0,255)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(255,0,0)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
CYAN = display.create_pen(0,255,255)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
YELLOW = display.create_pen(255, 255, 0)
    
def clean(): # Clear the screen to Black
    display.set_pen(BLACK)
    display.clear()

display.set_font("bitmap8") # Change the font
clean()
display.set_pen(RED)
display.text("World Time",40,200,460,8)
display.set_pen(BLUE)
display.text("http://worldtimeapi.org/api/timezone/Europe/London.txt",70,400,480,2)
display.text("Tony Goodhew, Leicester UK",120,450,480,2)
presto.update()
time.sleep(1)

clean()
display.set_pen(RED)

# Activate WiFi 
wlan = network.WLAN(network.STA_IF)
wlan.active(True)

wlan.connect(WIFI_SSID, WIFI_PASSWORD)
max_wait = 30
while max_wait > 0:
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print("Waiting for Wi-Fi connection...")
    display.set_pen(RED)
    display.text("Waiting for Wi-Fi connection...",10,200,460,5)
    presto.update()
    time.sleep(1)

if wlan.status() != 3:
    raise RuntimeError("Network connection failed")
else:
    print("Connected to Wi-Fi network.")
    print(wlan.ifconfig())

clean()
display.set_pen(GREEN)
display.text("Connected to WiFi",50,200,460,5)
display.set_pen(BLUE)
display.text("   Processing",70,260,460,5)
presto.update()

response = requests.get("http://worldtimeapi.org/api/timezone/Europe/London.txt")
print(response)
response.close()


What am I doing wrong?

Seems like the site is currently not available. All you can do is put the get-request in a try-catch block.

…same here.

…this is just a workaround in case the site is down for seconds.
The site is down for days…

This does not seem to be a reliable source to incorporate functions and maybe decisions (based on timing and location) in your code…

Indeed, see WorldTimeAPI: down for maintenance

For my in house sensors, I am running a very simple python-server on my Pi (home-server) that replicates the functionality. Since this is a full-blown Linux-system on the Pi, it has the complete Olson-database with timezones, rulesets and so on so it will always have the correct local time.

Since my code is still worldtimeapi.org compatible, I can still share it and everybody can use it worldwide. If you only write code for yourself, than you can of course use NTP and tinker with offsets and do the DST calculation yourself.