Skip to content

Commit 3038eeb

Browse files
sync time
1 parent ef4a6e2 commit 3038eeb

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

internal_filesystem/builtin/apps/com.example.wificonf/assets/auto_connect.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ def auto_connect():
5353
print("auto_connect: no known networks connected")
5454
return False
5555

56+
def sync_time():
57+
import ntptime
58+
print("Synchronizing clock...")
59+
# Set the NTP server and sync time
60+
ntptime.host = 'pool.ntp.org' # Set NTP server
61+
try:
62+
print('Syncing time with', ntptime.host)
63+
ntptime.settime() # Fetch and set time (in UTC)
64+
print('Time synced successfully')
65+
except Exception as e:
66+
print('Failed to sync time:', e)
5667

5768
def attempt_connecting(ssid,password):
5869
print(f"auto_connect.py attempt_connecting: Attempting to connect to SSID: {ssid}")
@@ -61,6 +72,7 @@ def attempt_connecting(ssid,password):
6172
for i in range(10):
6273
if wlan.isconnected():
6374
print(f"auto_connect.py attempt_connecting: Connected to {ssid} after {i+1} seconds")
75+
sync_time()
6476
return True
6577
elif not wlan.active(): # wificonf app or others might stop the wifi, no point in continuing then
6678
print("auto_connect.py attempt_connecting: Someone disabled wifi, bailing out...")

internal_filesystem/lib/mpos/ui.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,9 @@ def create_notification_bar():
152152
# Update time
153153
import time
154154
def update_time(timer):
155-
ticks = time.ticks_ms()
156-
hours = (ticks // 3600000) % 24
157-
minutes = (ticks // 60000) % 60
158-
seconds = (ticks // 1000) % 60
159-
#milliseconds = ticks % 1000
155+
hours = time.localtime()[3]
156+
minutes = time.localtime()[4]
157+
seconds = time.localtime()[5]
160158
time_label.set_text(f"{hours:02d}:{minutes:02d}:{seconds:02d}")
161159

162160
can_check_network = False

0 commit comments

Comments
 (0)