Skip to content

Commit a289017

Browse files
authored
Merge pull request #3 from jedie/develop
Develop
2 parents 53ac822 + 66429dd commit a289017

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
time.sleep(1)
1212

1313
from watchdog import watchdog # noqa isort:skip
14-
from leds import power_led # noqa isort:skip
15-
from ntp import ntp_sync # noqa isort:skip
1614
from 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

1918
print('watchdog:', watchdog)
2019
print('wifi:', wifi)

src/ntp.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ntptime
77
import utime as time
88
from watchdog import watchdog
9+
from wifi import wifi # noqa isort:skip
910

1011
rtc = 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:

src/webswitch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def send_web_page(writer, message=''):
4444

4545
@asyncio.coroutine
4646
def request_handler(reader, writer):
47-
print('\nWait for request...')
47+
print('\nWait 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

144144
def 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)

0 commit comments

Comments
 (0)