---
title: "W5500 and Circuitpython examples (socket library)."
url: "https://maker.wiznet.io/forum/15121"
markdown_url: "https://maker.wiznet.io/forum/15121/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "Henrik"
created: "2024-01-15T18:57:06+09:00"
last_activity: "2024-01-15T19:05:43+09:00"
language: "en"
views: 486
replies: 0
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 and Circuitpython examples (socket library).

## Question

Asked by Henrik on 2024-01-15 in Ethernet Chips.

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:

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/0/0601bca26344e8eded02f5b5b9102fe4f90e93af.png) [circuitpython.org](https://circuitpython.org/board/wiznet_w5500_evb_pico/)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/c/cd1e4df215b6b1f6348052366315ff801a24e184.jpeg)

### [CircuitPython - W5500-EVB-Pico Download](https://circuitpython.org/board/wiznet_w5500_evb_pico/)

W5500-EVB-Pico is a microcontroller evaluation board based on the Raspberry Pi RP2040 and fully hardwired TCP/IP controller W5500 – and basically works the same as Raspberry Pi Pico board but with additional Ethernet via W5500. Raspberry Pi Pico...

Installed CircuitPython onto W5500-EVB-Pico

Downloaded everything (as .zip archive) from:

- [GitHub - Wiznet/RP2040-HAT-CircuitPython](https://github.com/Wiznet/RP2040-HAT-CircuitPython)

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: 192.168.10.187
```

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

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

```
socket connected
socket object at 0x20018990> ('192.168.10.198', 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
SPI0_SCK = board.GP18
SPI0_TX = board.GP19
SPI0_RX = board.GP16
SPI0_CSn = board.GP17

##reset
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
time.sleep(1)
ethernetRst.value = True

# # Initialize ethernet interface without DHCP
# eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC, debug=False)
# # Set network configuration
# eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)

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

# Initialize a socket for our server
socket.set_interface(eth)
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
    eth.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 (
            SNSR_SOCK_FIN_WAIT,
        ):
            print("socket SNSR_SOCK_FIN_WAIT")
            conn.close()
            conn = None
        elif conn._status in (
            SNSR_SOCK_CLOSE_WAIT,
        ):
            print("socket SNSR_SOCK_CLOSE_WAIT")
            conn.disconnect()
            conn.close()
            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!

---

Source: https://maker.wiznet.io/forum/15121
