mirror of
https://github.com/Gabi-Zar/Pico-2W-Computer-Power-Controller.git
synced 2026-08-02 23:36:23 +02:00
Add wifi connection
This commit is contained in:
33
main.py
Normal file
33
main.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
import network
|
||||
|
||||
from config import (
|
||||
WIFI_PASSWORD,
|
||||
WIFI_SSID,
|
||||
)
|
||||
|
||||
def connect_wifi():
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
|
||||
while True:
|
||||
print("Connecting to Wi-Fi...")
|
||||
|
||||
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
|
||||
|
||||
for _ in range(10):
|
||||
if wlan.status() == 3:
|
||||
print("connected :", wlan.ifconfig()[0])
|
||||
return wlan
|
||||
|
||||
if wlan.status() < 0:
|
||||
break
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
print(f"network connection failed (status={wlan.status()})")
|
||||
wlan.disconnect()
|
||||
time.sleep(2)
|
||||
|
||||
connect_wifi()
|
||||
|
||||
Reference in New Issue
Block a user