dual ethernet in esp32 port
Description
As per Micropython documentation it is possible to have (at least) 2 LAN ports.
https://docs.micropython.org/en/v1.24.0/library/network.LAN.html#network.LAN
id is the number of the Ethernet port, either 0 or 1.
However, in the esp32 port the LAN object is implemented as a static object.
As per @robert-hh this requires convert this object into a dynamic object and the effort would not be substantial. It's unlikely I can pitch in development, but I may be able to help testing.
Code Size
My use case is in bridging 2 networks that for security reason ( or other reasons ), need to remains isolated ( at level 2/3 ISO layers). No ethernet packets or IP packets between networks. However, it is OK to exchange data at application layer on verified appliances.
This case is frequent in industrial setups, where multiple networks are isolated but frequently there is need to exchange information between them. The simplest case if between devices isolated in network due to lack of security compliance and the rest of IT infra. Think an old robot still using Windows X that cost millions to replace. Or an old automation system, a third party system that cannot be audited/patched.
Bandwidth is not an issue frequently in these systems, either wise bare metal programing is required.
This is the code I have been testing on a ESP module prog 1
mport network, time, urequests
from machine import Pin, SPI,reset
import socket
a = False
#if a :
spi1 = SPI(1, miso=Pin(12), mosi=Pin(13), sck=Pin(14))
#spi.write(b'\x00\x39\x00')
#print(spi.read(1))
lan1 = network.LAN(0,phy_type=network.PHY_W5500, phy_addr=0, cs=Pin(15), int=Pin(11), spi=spi1)
lan1.config(mac=b"\x02\x00\x00\x12\x34\x56")
lan1.active(1)
time.sleep(1)
while lan1.status() != network.ETH_GOT_IP:
print(".", end="")
time.sleep(1)
print(f" {lan1.ipconfig('addr4')}, {network.ipconfig('dns')}")
print(f" {lan1.ifconfig()}")
#else:
spi2 = SPI(2, miso=Pin(47), mosi=Pin(21), sck=Pin(18))
#spi.write(b'\x00\x39\x00')
#print(spi.read(1))
lan2 = network.LAN(1,phy_type=network.PHY_W5500, phy_addr=1, cs=Pin(16), int=Pin(17), spi=spi2)
lan2.config(mac=b"\x02\x00\x00\x12\x34\x57")
lan2.active(1)
time.sleep(1)
while lan2.status() != network.ETH_GOT_IP:
print(".", end="")
time.sleep(1)
print(f" {lan2.ipconfig('addr4')}, {network.ipconfig('dns')}")
print(f" {lan2.ifconfig()}")
With the net results of
lan1 is lan2
>>>True
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
doc: Add documentation for SPI Ethernet devices on esp32 port.
Summary
This was inspired by some confusion on Discord about how to use WIZnet5K on ESP32.
As well as adding documentation for the SPI Ethernet "mode" of network.LAN on ESP32, this PR adds some cross-reference links between related network documentation pages.
This work was funded through GitHub Sponsors.
Testing
- I set up an ESP32-S3 with a W5500 breakout and ran the sample code which has been added as part of the new doc section.
Trade-offs and Alternatives
- We could try to move this documentation out of esp32 quickref and into the
network.LANdoc, but I think it'll be even messier to do it that way.