@@ -28,33 +28,7 @@ def getdate(passedIn=""):
28
28
print ("Attempting to set Date/Time" ,end = "" )
29
29
30
30
try :
31
- print (" Using http worldtimeapi.org..." ,end = "" )
32
- Pydos_wifi .timeout = 1000
33
- response = Pydos_wifi .get ("http://worldtimeapi.org/api/ip" ,None ,True )
34
- time_data = Pydos_wifi .json ()
35
-
36
- if passedIn == "" :
37
- tz_hour_offset = int (time_data ['utc_offset' ][0 :3 ])
38
- tz_min_offset = int (time_data ['utc_offset' ][4 :6 ])
39
- if (tz_hour_offset < 0 ):
40
- tz_min_offset *= - 1
41
- else :
42
- tz_hour_offset = int (passedIn )
43
- tz_min_offset = 0
44
-
45
- unixtime = int (time_data ['unixtime' ] + (tz_hour_offset * 60 * 60 )) + (tz_min_offset * 60 )
46
- ltime = time .localtime (unixtime )
47
-
48
- if sys .implementation .name .upper () == "MICROPYTHON" :
49
- machine .RTC ().datetime (tuple ([ltime [0 ]- (time .localtime (0 )[0 ]- 1970 )]+ [ltime [i ] for i in [1 ,2 ,6 ,3 ,4 ,5 ,7 ]]))
50
- else :
51
- rtc .RTC ().datetime = ltime
52
-
53
- print ("\n Time and Date successfully set" ,end = "" )
54
- envVars ['errorlevel' ] = '0'
55
-
56
- except :
57
- print ( " FAILED. Trying NTP..." ,end = "" )
31
+ print ( "Trying NTP..." ,end = "" )
58
32
59
33
if passedIn == "" :
60
34
tz_hour_offset = - 4
@@ -117,6 +91,33 @@ def getdate(passedIn=""):
117
91
print ("\n Time and Date successfully set" ,end = "" )
118
92
envVars ['errorlevel' ] = '0'
119
93
94
+ except :
95
+
96
+ print ("FAILED. Trying http worldtimeapi.org..." ,end = "" )
97
+ Pydos_wifi .timeout = 1000
98
+ response = Pydos_wifi .get ("http://worldtimeapi.org/api/ip" ,None ,True )
99
+ time_data = Pydos_wifi .json ()
100
+
101
+ if passedIn == "" :
102
+ tz_hour_offset = int (time_data ['utc_offset' ][0 :3 ])
103
+ tz_min_offset = int (time_data ['utc_offset' ][4 :6 ])
104
+ if (tz_hour_offset < 0 ):
105
+ tz_min_offset *= - 1
106
+ else :
107
+ tz_hour_offset = int (passedIn )
108
+ tz_min_offset = 0
109
+
110
+ unixtime = int (time_data ['unixtime' ] + (tz_hour_offset * 60 * 60 )) + (tz_min_offset * 60 )
111
+ ltime = time .localtime (unixtime )
112
+
113
+ if sys .implementation .name .upper () == "MICROPYTHON" :
114
+ machine .RTC ().datetime (tuple ([ltime [0 ]- (time .localtime (0 )[0 ]- 1970 )]+ [ltime [i ] for i in [1 ,2 ,6 ,3 ,4 ,5 ,7 ]]))
115
+ else :
116
+ rtc .RTC ().datetime = ltime
117
+
118
+ print ("\n Time and Date successfully set" ,end = "" )
119
+ envVars ['errorlevel' ] = '0'
120
+
120
121
print ()
121
122
Pydos_wifi .close ()
122
123
0 commit comments