diff --git a/internal_filesystem/builtin/apps/com.example.wificonf/assets/auto_connect.py b/internal_filesystem/builtin/apps/com.example.wificonf/assets/auto_connect.py index 7cebabc7..06b82d43 100644 --- a/internal_filesystem/builtin/apps/com.example.wificonf/assets/auto_connect.py +++ b/internal_filesystem/builtin/apps/com.example.wificonf/assets/auto_connect.py @@ -53,6 +53,17 @@ def auto_connect(): print("auto_connect: no known networks connected") return False +def sync_time(): + import ntptime + print("Synchronizing clock...") + # Set the NTP server and sync time + ntptime.host = 'pool.ntp.org' # Set NTP server + try: + print('Syncing time with', ntptime.host) + ntptime.settime() # Fetch and set time (in UTC) + print('Time synced successfully') + except Exception as e: + print('Failed to sync time:', e) def attempt_connecting(ssid,password): print(f"auto_connect.py attempt_connecting: Attempting to connect to SSID: {ssid}") @@ -61,6 +72,7 @@ def attempt_connecting(ssid,password): for i in range(10): if wlan.isconnected(): print(f"auto_connect.py attempt_connecting: Connected to {ssid} after {i+1} seconds") + sync_time() return True elif not wlan.active(): # wificonf app or others might stop the wifi, no point in continuing then print("auto_connect.py attempt_connecting: Someone disabled wifi, bailing out...") diff --git a/internal_filesystem/lib/mpos/ui.py b/internal_filesystem/lib/mpos/ui.py index 2193544f..cafda599 100644 --- a/internal_filesystem/lib/mpos/ui.py +++ b/internal_filesystem/lib/mpos/ui.py @@ -152,11 +152,9 @@ def create_notification_bar(): # Update time import time def update_time(timer): - ticks = time.ticks_ms() - hours = (ticks // 3600000) % 24 - minutes = (ticks // 60000) % 60 - seconds = (ticks // 1000) % 60 - #milliseconds = ticks % 1000 + hours = time.localtime()[3] + minutes = time.localtime()[4] + seconds = time.localtime()[5] time_label.set_text(f"{hours:02d}:{minutes:02d}:{seconds:02d}") can_check_network = False