Delay - TIME OUT - with Internet Time

MicroPython pico2_w_2025_09_19,   on 2025-09-26; Pimoroni Pico LiPo 2XL W with RP2350

Type "help()" for more information.

>>> %Run -c $EDITOR_CONTENT

MPY: soft reboot
waiting for connection...
waiting for connection...
waiting for connection...
waiting for connection...
connected
ip = 192.168.0.52
Error: [Errno 110] ETIMEDOUT
Error: [Errno 110] ETIMEDOUT
(2025, 12, 9, 12, 3, 56, 1, 343)
 
Tue 9 Dec 2025 12:3:56
>>> 

Code used:

# From: https://gist.github.com/aallan/581ecf4dc92cd53e3a415b7c33a1147c
# Modified by Tony Goodhew 8 Dec 2025 to recover from TIME OUT problem with ntp.com
import network
import socket
import time
import struct
from secrets import WIFI_SSID, WIFI_PASSWORD
from machine import Pin

NTP_DELTA = 2208988800

'''
Try these
   0.uk.pool.ntp.org     1.uk.pool.ntp.org     2.uk.pool.ntp.org     3.uk.pool.ntp.org
'''
host = "1.uk.pool.ntp.org"

led = Pin("LED", Pin.OUT)
months = ["Jan", "Feb", "Mar", "Apr", "May","Jun","Jul", "Aug", "Sep", "Oct","Nov","Dec"]
wd =["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

def set_time():
    NTP_QUERY = bytearray(48)
    NTP_QUERY[0] = 0x1B
    addr = socket.getaddrinfo(host, 123)[0][-1]
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    got_it = False
    while got_it == False:
        try:
            s.settimeout(5)
            res = s.sendto(NTP_QUERY, addr)
            msg = s.recv(48)

        except Exception as e:
            print(f"Error: {str(e)}")            
        else:
            got_it = True
                    
    s.close()    
    val = struct.unpack("!I", msg[40:44])[0]
    t = val - NTP_DELTA    
    tm = time.gmtime(t)
    machine.RTC().datetime((tm[0], tm[1], tm[2], tm[6] + 1, tm[3], tm[4], tm[5], 0))

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)

max_wait = 10
while max_wait > 0:
    if wlan.status() < 0 or wlan.status() >= 3:
        break
    max_wait -= 1
    print('waiting for connection...')
    time.sleep(1)

if wlan.status() != 3:
    raise RuntimeError('network connection failed')
else:
    print('connected')
    status = wlan.ifconfig()
    print( 'ip = ' + status[0] )

led.on()
set_time()
print(time.localtime())
led.off()

print(" ")
year,mon,day,h,m,s,weekday,x = time.localtime()
now = str(h)+":"+str(m)+":"+str(s)
date = str(day)+" " + months[mon-1] + " "+str(year)

'''
print(now)
print(date)
print(wd[weekday])
'''

print(wd[weekday] + " " + date + " " + now)

Is there another site which is more reliable where you can pic up the time without waiting so long. I’m looking for a simple text page with the hours and minutes being updated.

NTP is standardized, you can use any ntp server and there are thousands, e.g. 0.opensuse.pool.ntp.org (replace the zero with anything from 0-3).

The best bet is to use your own router if it provides time within your network. Which could very well be possible. Or an ntp-host from your provider.