---
title: "Micropython-ESP32-W5500 (Wiznet)"
url: "https://maker.wiznet.io/louis_m/projects/micropython-esp32-w5500-wiznet/"
markdown_url: "https://maker.wiznet.io/louis_m/projects/micropython-esp32-w5500-wiznet/md"
type: "UCC: User Created Content"
author: "Ayyoubzadeh"
author_url: "https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#micropython-esp32-w5500-wiznet"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Ayyoubzadeh"
original_url: "https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#micropython-esp32-w5500-wiznet"
published: "2023-11-02"
language: "en"
hardware: ["WIZnet W5500", "Adafruit Feather HUZZAH with ESP8266 WiFi"]
likes: 0
views: 1245
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Micropython-ESP32-W5500 (Wiznet)

> Connect your ESP32 to W5500 (Wiznet) ethernet module and use Python requests as http client

Original author: Ayyoubzadeh (source: https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#micropython-esp32-w5500-wiznet)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))
- **Adafruit Feather HUZZAH with ESP8266 WiFi** x 1 ([docs](https://www.adafruit.com/product/2821))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

Connect your ESP32 to W5500 (Wiznet) ethernet module and use Python requests as http client

[![Untitled](https://user-images.githubusercontent.com/92551110/189515479-bfadad62-0bf1-4efc-84bb-ae88b58ec12a.png)](https://user-images.githubusercontent.com/92551110/189515479-bfadad62-0bf1-4efc-84bb-ae88b58ec12a.png)

## [Hardware](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#hardware)

ESP32 ESP-WROOM-32
W5500 (or W5100)

## [Firmware](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#firmware)

Micropython

## [Tools](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#tools)

python ampy (install using pip)

```plaintext
pip install adafruit-ampy
```

## [Wiring](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#wiring)

| ESP-32 | W5500 |
| --- | --- |
| 3V3 | V |
| GND | G |
| GPIO5(VSPI_CS) | CS |
| GPIO18(VSPI_CLK) | SCK |
| GPIO23(VSPI_MOSI) | MO |
| GPIO19(VSPI_MISO) | MI |
| GPIO34 | RST |

## [Instructions](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#instructions)

1. Upload wiznet5k.mpy, wiznet5k_dhcp.mpy, wiznet5k_dns.mpy, wiznet5k_socket.mpy,sma_esp32_w5500_requests with ampy

example: (replace COM9 with your esp32 connected serial port)

```plaintext
ampy --port COM9 put wiznet5k.mpy
ampy --port COM9 put wiznet5k_dhcp.mpy
ampy --port COM9 put wiznet5k_dns.mpy
ampy --port COM9 put wiznet5k_socket.mpy
ampy --port COM9 put sma_esp32_w5500_requests.mpy
```

1. run main.py or below code:

```plaintext
from wiznet5k import WIZNET5K
from machine import Pin, SPI
import wiznet5k_socket as socket
import time
import struct
import sma_esp32_w5500_requests as requests



spi = SPI(2)
cs = Pin(5,Pin.OUT)
rst=Pin(34)
nic = WIZNET5K(spi,cs,rst)

TEXT_URL = "http://quietlushbrightverse.neverssl.com/online/"


print("Chip Version:", nic.chip)
print("MAC Address:", [hex(i) for i in nic.mac_address])
print("My IP address is:", nic.pretty_ip(nic.ip_address))
print("IP lookup google.com: %s" %nic.pretty_ip(nic.get_host_by_name("google.com")))

# Initialize a requests object with a socket and ethernet interface
requests.set_socket(socket, nic)


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

print("Done!")
```

## [Limitations](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#limitations)

Only Works with http (not https)

## [How to login in asp.net forms with getting a cookie (forms-based authentication)](https://github.com/Ayyoubzadeh/ESP32-Wiznet-W500-Micropython#how-to-login-in-aspnet-forms-with-getting-a-cookie-forms-based-authentication)

First we need to get login page after that we need to post the username and password with __VIEWSTATE of the page, Finally, we need to send the cookie for private pages. in this example the login page named logon.aspx and the private page is default.aspx .

```plaintext
from wiznet5k import WIZNET5K
from machine import Pin, SPI
import wiznet5k_socket as socket
import sma_esp32_w5500_requests as requests

def findVal(txt,tag):
    g=txt[txt.find(tag):]
    g=g[g.find("value"):]
    g=g[:g.find("/>")]
    g=g.strip()
    g=g.replace("value=\"","")
    g=g[:-1] # remove "
    return g

spi = SPI(2)
cs = Pin(5,Pin.OUT)
rst=Pin(34)
nic = WIZNET5K(spi,cs,rst)


print("Chip Version:", nic.chip)
print("MAC Address:", [hex(i) for i in nic.mac_address])
print("My IP address is:", nic.pretty_ip(nic.ip_address))


requests.set_socket(socket, nic)
url = 'http://win.smait.ir/logon.aspx'
g = requests.get(url).text
payload ={}
payload['__EVENTTARGET']=""
payload['__EVENTARGUMENT']=""
payload['__VIEWSTATE']=findVal(g,'__VIEWSTATE')
payload['__VIEWSTATEGENERATOR']=findVal(g,'__VIEWSTATEGENERATOR')
payload['__EVENTVALIDATION']=findVal(g,'__EVENTVALIDATION')
payload['txtUserName']="1"
payload['txtUserPass']="2"
payload['Button1']="Login"
print(payload)


p = requests.post(url, data=payload)
print(p.headers)
cookie=p.headers['set-cookie'].split('; expires=')[0]
print(cookie)
p2 = requests.get('http://win.smait.ir/default.aspx', headers={"Cookie":cookie})
print(p2.text)
```

---

Source: https://maker.wiznet.io/louis_m/projects/micropython-esp32-w5500-wiznet/
