# W55RP20-EVB-PICO simple server example # # To test, you can use your webbrowser # you have to find out the ip-address of the board first ( should be printed in the Micropython console on startup ) # # example: http://192.168.178.48/ # # 2025-03-11 ch # # !! Use it at you own risk, no warraties, only for test purposes, no security implemented !! # from machine import Pin, WIZNET_PIO_SPI import network import socket import time import machine spi = WIZNET_PIO_SPI(baudrate=31_250_000, mosi=Pin(23), miso=Pin(22), sck=Pin(21)) # W55RP20 PIO_SPI cs = machine.Pin(5, machine.Pin.OUT) # Initialize Ethernet (W5500) eth = network.WIZNET5K(spi, Pin(20), Pin(25)) # spi, cs, reset pin eth.active(True) # Wait for IP address while not eth.isconnected(): print("Waiting for Ethernet connection...") time.sleep(1) print("Connected! IP:", eth.ifconfig()) # Simple HTTP Server def http_server(): server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(('0.0.0.0', 80)) server_socket.listen(5) print('Listening on port 80...') while True: conn, addr = server_socket.accept() print('Connection from', addr) request = conn.recv(1024) print('Request:', request) response = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\nHello from MicroPython Ethernet!" conn.send(response.encode()) conn.close() # Start the server http_server()