File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1111 time .sleep (1 )
1212
1313from watchdog import watchdog # noqa isort:skip
14- from leds import power_led # noqa isort:skip
15- from ntp import ntp_sync # noqa isort:skip
1614from wifi import wifi # noqa isort:skip
17-
15+ from ntp import ntp_sync # noqa isort:skip
16+ from leds import power_led # noqa isort:skip
1817
1918print ('watchdog:' , watchdog )
2019print ('wifi:' , wifi )
Original file line number Diff line number Diff line change 66import ntptime
77import utime as time
88from watchdog import watchdog
9+ from wifi import wifi # noqa isort:skip
910
1011rtc = machine .RTC ()
1112
@@ -39,6 +40,11 @@ def _timer_callback(self, timer):
3940 def _sync (self ):
4041 print ('Synchronize time from %r ...' % ntptime .host )
4142 gc .collect ()
43+
44+ if not wifi .is_connected :
45+ print ('Skip NTP sync: not connectet to a WiFi!' )
46+ return
47+
4248 print ('old UTC:' , rtc .datetime ())
4349 s = 1
4450 while True :
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def send_web_page(writer, message=''):
4444
4545@asyncio .coroutine
4646def request_handler (reader , writer ):
47- print ('\n Wait for request...' )
47+ print ('\n Wait for request on %s ...' % wifi . station . ifconfig ()[ 0 ] )
4848 gc .collect ()
4949
5050 address = writer .get_extra_info ('peername' )
@@ -142,8 +142,13 @@ def request_handler(reader, writer):
142142
143143
144144def main ():
145- print ('start webserver...' )
146-
145+ s = 1
146+ while not wifi .is_connected :
147+ print ('Wait for WiFi connection %s sec.' % s )
148+ time .sleep (s )
149+ s += 5
150+
151+ print ('Start webserver on %s...' % wifi .station .ifconfig ()[0 ])
147152 loop = asyncio .get_event_loop ()
148153
149154 coro = asyncio .start_server (request_handler , '0.0.0.0' , 80 )
You can’t perform that action at this time.
0 commit comments