Overview
W5500 Ethernet chip (via WIZ850io) enables SPI-based Ethernet communication on the SP2302, creating a second Ethernet interface (eth1
). This interface can fully support TCP server, TCP client, and UDP socket communication, allowing you to develop embedded applications like device controllers, IoT gateways, or data relays.
- WIZ850io properly wired via SPI to SP2302
- Dual-port firmware flashed to SP2302 with support for
eth1
Network check:
bash
複製編輯
ip addr show eth1
- Network check: ip addr show eth1
Assign a static IP or use DHCP: Example netplan:
yaml network: version: 2 ethernets: eth1: dhcp4: yes
- Assign a static IP or use DHCP: Example netplan:yaml複製編輯network: version: 2 ethernets: eth1: dhcp4: yes
Apply:
bash
sudo netplan apply
Testing TCP & UDP on W5500 (eth1)All examples below use1. TCP Server on W5500Python TCP Server Codeeth1
(W5500) for communication. Replace IPs with your actualeth1
IP when needed.
python
# tcp_server_w5500.py
import socket
HOST = '192.168.2.50' # eth1 IP
PORT = 5000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() print(f"[+] Listening on {HOST}:{PORT}") conn, addr = s.accept() with conn: print(f"[✓] Connected by {addr}") while True: data = conn.recv(1024) if not data: break print(f"[<] Received: {data.decode()}") conn.sendall(b"ACK: " + data)
Run:
bash
python3 tcp_server_w5500.py
2. TCP Client on W5500Python TCP Client Codepython # tcp_client_w5500.py
import socket
SERVER_IP = '192.168.2.100' # Remote server IP
PORT = 5000
LOCAL_IP = '192.168.2.50' # eth1 IP
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((LOCAL_IP, 0)) # Bind to eth1 s.connect((SERVER_IP, PORT)) s.sendall(b"Hello from W5500 client!") data = s.recv(1024) print(f"[<] Received: {data.decode()}")
3. UDP Communication on W5500Python UDP Echo Serverpython # udp_server_w5500.py
import socket
HOST = '192.168.2.50' # eth1 IP
PORT = 6000
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.bind((HOST, PORT)) print(f"[+] UDP Server listening on {HOST}:{PORT}") while True: data, addr = s.recvfrom(1024) print(f"[<] Received from {addr}: {data.decode()}") s.sendto(b"ACK: " + data, addr)
Python UDP Clientpython # udp_client_w5500.py
import socket
SERVER_IP = '192.168.2.100'
PORT = 6000
LOCAL_IP = '192.168.2.50'
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.bind((LOCAL_IP, 0)) # Bind to W5500 s.sendto(b"Hello UDP", (SERVER_IP, PORT)) data, addr = s.recvfrom(1024) print(f"[<] Reply: {data.decode()}")
Testing Tools- Hercules on a PC to test server/client interactions.
- Use
dmesg | grep eth1
to confirm driver is loaded - Confirm route to target IP using
ip route
- Monitor traffic with
tcpdump -i eth1
40 projects • 5 followers
Secure Pi: Linux-based solution powered by Cortex A5 chipset, delivering advanced security, versatility, and performance.
Comments