File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
builtin/apps/com.example.wificonf/assets Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff 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
5768def 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..." )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments