Skip to content

Wiznet5K with Particle Ethernet Featherwing #127

Description

@vacquah

I am using a repurposed particle xenon board with circuitpython with a particle ethernet featherwing. I have the same issue as this - the ethernet connection works with a fixed IP but fails with dhcp. Shows an error:

* socket_available called on socket 4, protocol 2
* socket_available called on socket 4, protocol 2
* socket_available called on socket 4, protocol 2
* socket_available called on socket 4, protocol 2
* socket_available called on socket 4, protocol 2
* socket_available called on socket 4, protocol 2
*** Closing socket #4
Traceback (most recent call last):
  File "code.py", line 108, in <module>
  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 230, in __init__
RuntimeError: Failed to configure DHCP Server!

Code done running.

Here is my circuitpython code:

import board
import busio
import digitalio
import adafruit_requests as requests
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket


print("Wiznet5k WebClient Test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"

def get_mac(i2c_obj):
    "Read MAC from 24AA02E48 chip and return it"
    mac_addr = bytearray(6)
    while not i2c_obj.try_lock():
        pass
    i2c_obj.writeto(0x50, bytearray((0xFA,)))
    i2c_obj.readfrom_into(0x50, mac_addr, start=0, end=6)
    i2c_obj.unlock()
    return mac_addr

# Initialize SPI bus
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Chip Select for Particle Ethernet FeatherWing
cs = digitalio.DigitalInOut(board.D5)

try:
    # Initialize the I2C bus to read the MAC
    i2c = busio.I2C(board.SCL, board.SDA)
    # Read the MAC from the 24AA02E48 chip
    mac = get_mac(i2c)
except (RuntimeError, OSError):
    # Hard coded MAC if there is no 24AA02E48
    mac = b"\xFE\xED\xDE\xAD\xBE\xEF"

# Initialize Ethernet interface with DHCP
eth = WIZNET5K(spi_bus, cs, mac=mac, is_dhcp=True, debug=True)

print(eth.detect_w5500())
print(eth.link_status)

# 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"))
    ) # type: ignore

#eth._debug = True
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print('-'*40)
print(r.text)
print('-'*40)
r.close()

print()
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print('-'*40)
print(r.json())
print('-'*40)
r.close()

print("Done!")

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions