W5500 and Circuitpython examples (socket library).

I’m playing around with CircuitPython on a W5500-EVB-Pico.

I’m trying to get the basic Loopback example program to work but can’t.
Here’s what I’ve done.

Downloaded CircuitPython 8.2.9 for W5500-EVB-Pico from:

Installed CircuitPython onto W5500-EVB-Pico

Downloaded everything (as .zip archive) from:

From the unzipped RP2040-HAT-CircuitPython-master folder, copied

  • adafruit_bus_device (folder)
  • adafruit_wiznet5k (folder)
  • adafruit_requests.py (file)
    to the lib folder on the W5500-EVB-Pico

In Thonny open and run W5x00_Loopback.py

At this point I get the following in the Shell:

Wiznet5k Loopback Test (DHCP)
server listen
Chip Version: w5500
MAC Address: ['0x0', '0x1', '0x2', '0x3', '0x4', '0x5']
My IP address is:

which tells me the thing is “working” and has aquired an IP-address on my network - great.

Now, I start Putty and connect to and get this:

socket connected
socket object at 0x20018990> ('', 61839)
Traceback (most recent call last):
  File "<stdin>", line 76, in <module>
AttributeError: 'socket' object has no attribute 'status'

The offending line 76 is here:

71    if conn is None:
72        conn, addr = server.accept()  # Wait for a connection from a client.
73        print("socket connected")
74        print(conn, addr)
75    else :
76        if conn.status in (
77            SNSR_SOCK_FIN_WAIT,
78        ):

Looking at the socket library it seems as if ‘status’ is private (or something) since it’s prepended with an underscode in the code.
If I change line 76 to if conn._status it does get passed that line but crashes on the next line where conn.‘something’ is accessed (conn.close(), conn.disconnec(), conn.available() and so on).
The “solution” is the same, change to conn._‘something’ but it just doesn’t feel right, there’s more to it than a missing underscore.

Can someone please exaplain what I’m doing wrong?

Here’s the complete code as it sits on the Pico

import board
import busio
import digitalio
import time
from adafruit_wiznet5k.adafruit_wiznet5k import *
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket

SPI0_SCK = board.GP18
SPI0_TX = board.GP19
SPI0_RX = board.GP16
SPI0_CSn = board.GP17

W5x00_RSTn = board.GP20

print("Wiznet5k Loopback Test (DHCP)")
# Setup your network configuration below
# random MAC, later should change this value on your vendor ID
MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
IP_ADDRESS = (192, 168, 1, 100)
SUBNET_MASK = (255, 255, 255, 0)
GATEWAY_ADDRESS = (192, 168, 1, 1)
DNS_SERVER = (8, 8, 8, 8)

led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT

ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
ethernetRst.direction = digitalio.Direction.OUTPUT

# For Adafruit Ethernet FeatherWing
cs = digitalio.DigitalInOut(SPI0_CSn)
# For Particle Ethernet FeatherWing
# cs = digitalio.DigitalInOut(board.D5)

spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

# Reset W5x00 first
ethernetRst.value = False
ethernetRst.value = True

# # Initialize ethernet interface without DHCP
# eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC, debug=False)
# # Set network configuration

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

# Initialize a socket for our server
server = socket.socket()  # Allocate socket for the server
server_ip = None  # IP address of server
server_port = 5000  # Port to listen on
server.bind((server_ip, server_port))  # Bind to IP and Port
server.listen()  # Begin listening for incoming clients
print("server listen")

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))

conn = None

while True:
    # Maintain DHCP lease

    if conn is None:
        conn, addr = server.accept()  # Wait for a connection from a client.
        print("socket connected")
        print(conn, addr)
    else :
        if conn._status in (
            print("socket SNSR_SOCK_FIN_WAIT")
            conn = None
        elif conn._status in (
            print("socket SNSR_SOCK_CLOSE_WAIT")
            conn = None
        else :
            # print("socket established", conn.status)
            avail = conn.available()
            if avail:
                # print("Received size:", avail)
                # data = conn.recv(0)
                data = conn.embed_recv(2048)
                if data:
                    print("DATA ptr", id(data), ",DATA Len: ", len(data))
                    conn.send(data)  # Echo message back to client

Thank you in advance!