-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTTP_Client.py
39 lines (32 loc) · 967 Bytes
/
HTTP_Client.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
from usocket import socket
from machine import Pin,WIZNET_PIO_SPI
import urequests
import network
import time
#W5x00 chip init
def w5x00_init():
spi = WIZNET_PIO_SPI(baudrate=31_250_000, mosi=Pin(23),miso=Pin(22),sck=Pin(21)) #W55RP20 PIO_SPI
nic = network.WIZNET5K(spi,Pin(20),Pin(25)) #spi,cs,reset pin
nic.active(True)
#None DHCP
nic.ifconfig(('192.168.11.20','255.255.255.0','192.168.11.1','8.8.8.8'))
#DHCP
#nic.ifconfig('dhcp')
print('IP address :', nic.ifconfig())
while not nic.isconnected():
time.sleep(1)
print(nic.regs())
def request():
r = urequests.get('http://httpbin.org/get')
#r.raise_for_status
print(r.status_code)
print(r.text)
r= urequests.post('http://httpbin.org/post', json={'WIZnet Test'})
if not r:
print('spreadsheet: no response received')
print(r.json())
def main():
w5x00_init()
request()
if __name__ == "__main__":
main()