34
34
35
35
gc .collect ()
36
36
LED = Pin (2 , Pin .OUT )
37
- #wdt = WDT()
38
37
i2c = I2C (sda = Pin (4 ), scl = Pin (5 ), freq = 250000 )
39
38
oled = OLED1306 (i2c )
40
39
wifi_sta = network .WLAN (network .STA_IF )
41
40
rtcc = RTC ()
42
41
rtcc .datetime ((1970 , 1 , 1 , 0 , 0 , 0 , 0 , 0 ))
42
+ ts = unix_timestamp ()
43
43
unx = unix (+ 6 )
44
- ts = unix_timestamp ("Asia" , "Dhaka" )
45
44
46
45
47
46
def connect_and_check_wifi_status ():
48
47
global ip , connection_status , LED_state
49
-
50
- #
48
+
51
49
sleep_ms (900 )
52
50
53
51
if (wifi_sta .isconnected ()):
@@ -59,66 +57,62 @@ def connect_and_check_wifi_status():
59
57
else :
60
58
wifi_sta .active (True )
61
59
wifi_sta .disconnect ()
62
- #
63
60
sleep_ms (30 )
64
61
wifi_sta .connect (WiFi_Credentials .SSID , WiFi_Credentials .password )
65
- #
66
62
sleep_ms (60 )
67
63
print ("Network Unavailable!" + "\r \n " )
68
64
LED_state ^= 0x01
69
65
LED .value (LED_state )
70
- #
71
66
sleep_ms (9 )
72
67
connection_status = False
73
68
74
69
70
+ oled .fill (oled .BLACK )
71
+ oled .show ()
72
+
73
+
75
74
while (True ):
76
- try :
77
- connect_and_check_wifi_status ()
78
- year , month , date , day , hour , minute , second , tz = rtcc .datetime ()
79
-
80
- oled .fill (oled .BLACK )
81
- oled .text ("Unix Time Sync " , 12 , 0 , oled .WHITE )
82
-
83
- if (past_second != second ):
84
- LED_state ^= 0x01
85
- LED .value (LED_state )
86
- oled .text ("Unix Time Sync " , 12 , 0 , oled .WHITE )
87
- oled .text (("Time: " + str ("%02u:" % hour ) + str ("%02u:" % minute ) + str ("%02u" % second )), 0 , 42 , oled .WHITE )
88
- oled .text (("Date: " + str ("%02u/" % date ) + str ("%02u/" % month ) + str ("%4u" % year )), 0 , 56 , oled .WHITE )
89
-
90
- print ("Time: " + str ("%02u:" % hour ) + str ("%02u:" % minute ) + str ("%02u" % second )
91
- + " Date: " + str ("%02u/" % date ) + str ("%02u/" % month ) + str ("%4u" % year ))
75
+ connect_and_check_wifi_status ()
76
+ year , month , date , day , hour , minute , second , tz = rtcc .datetime ()
77
+
78
+ oled .fill (oled .BLACK )
79
+ oled .text ("Unix Time Sync " , 8 , 0 , oled .WHITE )
80
+
81
+ if (second != past_second ):
82
+ LED_state ^= 0x01
83
+ LED .value (LED_state )
84
+ oled .text (("Time: " + str ("%02u:" % hour ) + str ("%02u:" % minute ) + str ("%02u" % second )), 0 , 42 , oled .WHITE )
85
+ oled .text (("Date: " + str ("%02u/" % date ) + str ("%02u/" % month ) + str ("%4u" % year )), 0 , 56 , oled .WHITE )
86
+
87
+ print ("Time: " + str ("%02u:" % hour ) + str ("%02u:" % minute ) + str ("%02u" % second )
88
+ + " Date: " + str ("%02u/" % date ) + str ("%02u/" % month ) + str ("%4u" % year ))
92
89
93
- if (connection_status == False ):
94
- oled .text ("Network Error!" , 0 , 14 , oled .WHITE )
95
- oled .text ("...." , 0 , 28 , oled .WHITE )
96
- time_sync_status = False
90
+ past_second = second
91
+
92
+ if (connection_status == False ):
93
+ oled .text ("Network Error!" , 0 , 14 , oled .WHITE )
94
+ oled .text ("...." , 0 , 28 , oled .WHITE )
95
+ time_sync_status = False
97
96
98
- else :
99
- if (time_sync_status == False ):
100
- if (second == 30 ):
101
- time_fetch_flag = True
102
- time_sync_status = True
103
-
104
- if (time_sync_status == True ):
105
- if (((hour % sync_hour ) == 0 ) and (minute == 0 ) and (second == 0 )):
106
- time_fetch_flag = True
107
-
108
- if (time_fetch_flag == True ):
109
- oled .text ("*" , 120 , 46 , oled .WHITE )
110
- unix_time_stamp = ts .fetch_data ()
111
- year , month , date , hour , minute , second = unx .unix_to_date_time (unix_time_stamp )
112
- rtcc .datetime ((year , month , date , day , hour , minute , second , tz ))
113
- time_fetch_flag = False
114
-
115
- oled .text (("WiFi: " + WiFi_Credentials .SSID ), 0 , 14 , oled .WHITE )
116
- oled .text (("UNIX:" + str ("%u" % unix_time_stamp )), 0 , 28 , oled .WHITE )
97
+ else :
98
+ if (time_sync_status == False ):
99
+ if (second == 30 ):
100
+ time_fetch_flag = True
101
+ time_sync_status = True
117
102
118
- oled .show ()
119
-
103
+ else :
104
+ if (((hour % sync_hour ) == 0 ) and (minute == 0 ) and (second == 0 )):
105
+ time_fetch_flag = True
106
+
107
+ if (time_fetch_flag == True ):
108
+ oled .text ("*" , 120 , 46 , oled .WHITE )
109
+ unix_time_stamp = ts .fetch_data ()
110
+ year , month , date , hour , minute , second = unx .unix_to_date_time (unix_time_stamp )
111
+ rtcc .datetime ((year , month , date , day , hour , minute , second , tz ))
112
+ time_fetch_flag = False
120
113
121
- except KeyboardInterrupt :
122
- print ("End" )
123
-
114
+ oled .text (("WiFi: " + WiFi_Credentials .SSID ), 0 , 14 , oled .WHITE )
115
+ oled .text (("UNIX: " + str ("%u" % unix_time_stamp )), 0 , 28 , oled .WHITE )
116
+
117
+ oled .show ()
124
118
0 commit comments