forked from donskytech/micropython-raspberry-pi-pico
-
Notifications
You must be signed in to change notification settings - Fork 1
/
myWifi.py
29 lines (26 loc) · 749 Bytes
/
myWifi.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
import socket
from time import sleep
ssid='Y?OUR NETWORK'
password='YOUR PASSWORD'
def connect():
good_connection= False
while good_connection == False:
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
for ct in range(5):
if wlan.isconnected() == True:
good_connection= True
else:
print('Waiting for connection...', ct, end='\r')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'WiFi Connected on {ip}')
address = (ip, 80)
connection = socket.socket()
connection.bind(address)
connection.listen(1)
return connection
if __name__ == '__main__':
connect()