-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwificonnect.py
29 lines (25 loc) · 922 Bytes
/
wificonnect.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
import network
def connectSTA(ssid, password,name='MicroPython'):
global station
station = network.WLAN(network.STA_IF)
if not station.isconnected():
print('connecting to network...')
station.active(True)
print(ssid, password)
station.connect(ssid, password)
while not station.isconnected():
pass
station.config(dhcp_hostname = name)
print('network config:', station.ifconfig())
print("station.config(dhcp_hostname) =", station.config('dhcp_hostname'))
return station.ifconfig()[0]
def connectAP(name, password=''):
global ap
print('connecting the Access Point...')
ap = network.WLAN(network.AP_IF)
ap.active(True) #activating
ap.config(essid=name, password=password)
while ap.active() == False:
pass
print('Acces Point config:', ap.ifconfig())
return ap.ifconfig()[0]