-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (27 loc) · 745 Bytes
/
main.py
File metadata and controls
32 lines (27 loc) · 745 Bytes
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
import network
import socket
ssid = 'demo_ap'
password = '12345678'
nic=network.WLAN(network.STA_IF)
nic.active(True)
nic.connect(ssid, password)
while not nic.isconnected():
pass
print("wifi connection is done")
def http_get(url):
import socket
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
print("HTTP GET command is send");
while True:
data = s.recv(100)
if data:
print(str(data, 'utf8'), end='')
else:
print("conn is close")
break
s.close()
http_get('http://micropython.org/ks/test.html')