1
+ import board
2
+ import busio
3
+ import digitalio
4
+ import adafruit_requests as requests
5
+ from adafruit_wiznet5k .adafruit_wiznet5k import WIZNET5K
6
+ import adafruit_wiznet5k .adafruit_wiznet5k_socket as socket
7
+
8
+ TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
9
+
10
+ # Setup your network configuration below
11
+ IP_ADDRESS = (192 , 168 , 10 , 1 )
12
+ SUBNET_MASK = (255 , 255 , 0 , 0 )
13
+ GATEWAY_ADDRESS = (192 , 168 , 0 , 1 )
14
+ DNS_SERVER = (8 , 8 , 8 , 8 )
15
+
16
+ print ("Wiznet5k WebClient Test (no DHCP)" )
17
+
18
+ cs = digitalio .DigitalInOut (board .D10 )
19
+ spi_bus = busio .SPI (board .SCK , MOSI = board .MOSI , MISO = board .MISO )
20
+
21
+ # Initialize ethernet interface without DHCP
22
+ eth = WIZNET5K (spi_bus , cs , is_dhcp = False )
23
+
24
+ # Set network configuration
25
+ eth .ifconfig = (IP_ADDRESS , SUBNET_MASK , GATEWAY_ADDRESS , DNS_SERVER )
26
+
27
+ # Initialize a requests object with a socket and ethernet interface
28
+ requests .set_socket (socket , eth )
29
+
30
+ print ("Chip Version:" , eth .chip )
31
+ print ("MAC Address:" , [hex (i ) for i in eth .mac_address ])
32
+ print ("My IP address is:" , eth .pretty_ip (eth .ip_address ))
33
+ print ("IP lookup adafruit.com: %s" % eth .pretty_ip (eth .get_host_by_name ("adafruit.com" )))
34
+
35
+ #eth._debug = True
36
+ print ("Fetching text from" , TEXT_URL )
37
+ r = requests .get (TEXT_URL )
38
+ print ('-' * 40 )
39
+ print (r .text )
40
+ print ('-' * 40 )
41
+ r .close ()
42
+
43
+ print ()
0 commit comments