TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" # Setup your network configuration below IP_ADDRESS = (192, 168, 10, 1) SUBNET_MASK = (255, 255, 0, 0) GATEWAY_ADDRESS = (192, 168, 0, 1) DNS_SERVER = (8, 8, 8, 8) print("Wiznet5k WebClient Test (no DHCP)") cs = digitalio.DigitalInOut(board.D10) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Initialize ethernet interface without DHCP eth = WIZNET5K(spi_bus, cs, is_dhcp=False) # Set network configuration eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER) # Initialize a requests object with a socket and ethernet interface requests.set_socket(socket, eth) print("Chip Version:", eth.chip) print("MAC Address:", [hex(i) for i in eth.mac_address]) print("My IP address is:", eth.pretty_ip(eth.ip_address)) print("IP lookup adafruit.com: %s" % eth.pretty_ip(eth.get_host_by_name("adafruit.com"))) #eth._debug = True print("Fetching text from", TEXT_URL)
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket import adafruit_minimqtt.adafruit_minimqtt as MQTT from adafruit_io.adafruit_io import IO_MQTT # Get MQTT details and more from a secrets.py file try: from secrets import secrets except ImportError: print("MQTT secrets are kept in secrets.py, please add them there!") raise cs = DigitalInOut(board.D10) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) # Initialize ethernet interface with DHCP eth = WIZNET5K(spi_bus, cs) # Define callback functions which will be called when certain events happen. # pylint: disable=unused-argument def connected(client): # Connected function will be called when the client is connected to Adafruit IO. # This is a good place to subscribe to feed changes. The client parameter # passed to this function is the Adafruit IO MQTT client so you can make # calls against it easily. print("Connected to Adafruit IO! Listening for DemoFeed changes...") # Subscribe to changes on a feed named DemoFeed. client.subscribe("DemoFeed") def subscribe(client, userdata, topic, granted_qos):
import busio import digitalio import time from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket # WIZnet W5100S-EVB-Pico for Raspberry Pi Pico RP2040 SPI0_SCK = board.GP18 SPI0_TX = board.GP19 SPI0_RX = board.GP16 SPI0_CSn = board.GP17 W5x00_RSTn = board.GP15 cs = digitalio.DigitalInOut(SPI0_CSn) spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) eth = WIZNET5K(spi_bus, cs, is_dhcp=True, debug=False) ethernetRst = digitalio.DigitalInOut(W5x00_RSTn) ethernetRst.direction = digitalio.Direction.OUTPUT ethernetRst.value = False time.sleep(1) ethernetRst.value = True # edit host and port to match server HOST = "192.168.10.10" PORT = 5000 TIMEOUT = 5 INTERVAL = 5 MAXBUF = 256 while True:
led.brightness = 0.3 led[0] = (0, 0, 255) TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html" JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json" # PoE-FeatherWing connections cs = digitalio.DigitalInOut(board.D10) spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) i2c = busio.I2C(board.SCL, board.SDA) # Read the MAC from the 24AA02E48 chip mac = get_mac(i2c) # Initialize ethernet interface with DHCP and the MAC we have from the 24AA02E48 eth = WIZNET5K(spi_bus, cs, mac=mac, hostname="PoE-FeatherWing-{}") # Initialize a requests object with a socket and ethernet interface requests.set_socket(socket, eth) print("Chip Version:", eth.chip) print("MAC Address:", [hex(i) for i in eth.mac_address]) print("My IP address is:", eth.pretty_ip(eth.ip_address)) print("IP lookup adafruit.com: %s" % eth.pretty_ip(eth.get_host_by_name("adafruit.com"))) print("Fetching text from", TEXT_URL) r = requests.get(TEXT_URL) print("-" * 40) print(r.text) print("-" * 40)
i2c.readfrom_into(0x50, mac, start=0, end=6) i2c.unlock() except: pass print ("MAC address: {}".format(':'.join(['%02x' % i for i in mac]))) # Indicate whether we successfully read a MAC led.mac[mac != default_mac].value = True # DHCP retries dhcp_retries = 3 while dhcp_retries: try: # Initialize ethernet interface with DHCP and default MAC # If we used a unique MAC for each board we test, the DHCP server # would run out of IP addresses to lease eth = WIZNET5K(spi_bus, cs, mac=default_mac, hostname="PoE-FeatherWing-Fixture1") print("Chip Version:", eth.chip) print("My IP address is:", eth.pretty_ip(eth.ip_address)) # Indicate whether we successfully read the W5500 and got an IP led.ip[eth.chip == 'w5500'].value = True break except: dhcp_retries = dhcp_retries - 1 # Report if we didn't succeed in getting an IP from DHCP if not dhcp_retries: led.ip[False].value = True # Give power at least 5 seconds while time.time() < test_start_time + 5: