forked from makeuseofcode/pico-wireless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwireless.py
41 lines (33 loc) · 843 Bytes
/
wireless.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import time
import network
from machine import Pin
led = Pin("LED", Pin.OUT)
led.value(1) # LED On
led.value(0) # LED Off
ssid = 'Enter Your SSID'
password = 'enter your LAN password'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
s = 3
while s > 0:
s -= 1
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(0.5)
#print('connected')
status = wlan.ifconfig()
print( 'Connected to ' + ssid + '. ' + 'Device IP: ' + status[0] )