Skip to content

Commit b33df30

Browse files
committed
no need to connect to wifi right away
1 parent d8bbff2 commit b33df30

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ async def stop_server(request, response):
101101
await server.stop_server()
102102
shutdown = True
103103

104+
async def connnect_to_wifi():
105+
wifi_ssid = config.WIFI_SSID.strip()
106+
if wifi_ssid:
107+
wifi_password = config.WIFI_PASSWORD.strip()
108+
print("Connecting to wifi")
109+
success = await server.connect_wifi(wifi_ssid, wifi_password)
110+
if success:
111+
print("Connected to wifi")
112+
else:
113+
print("Failed to connect to wifi")
114+
return success
115+
else:
116+
print("No wifi ssid set")
117+
return False
118+
119+
104120
async def run_as_access_point(request, response):
105121
print("Running as access point")
106122
success = server.start_access_point('gurgleapps', 'gurgleapps')
@@ -112,6 +128,7 @@ async def run_as_access_point(request, response):
112128

113129
async def main():
114130
global shutdown
131+
await connnect_to_wifi()
115132
if config.BLINK_IP:
116133
await(server.blink_ip(led_pin = led, last_only = config.BLINK_LAST_ONLY))
117134
while not shutdown:
@@ -125,8 +142,8 @@ async def main():
125142
await asyncio.sleep(0.2)
126143

127144
server = GurgleAppsWebserver(
128-
config.WIFI_SSID,
129-
config.WIFI_PASSWORD,
145+
None,
146+
None,
130147
port=80,
131148
timeout=20,
132149
doc_root="/www",

0 commit comments

Comments
 (0)