Tutorial: Wired Networking — Ethernet (W5500 / RMII), USB-NCM & Failover

PylotOS treats all IPv4/IPv6 network interfaces under a single OS-owned controller (hal.net, HAL_OWNER_OS) so your TCP/UDP sockets, MQTT-HA, Web Dashboard, LAN AI MCP Bridge, and Asymmetric Recovery-OTA continue seamlessly across Ethernet, USB-NCM, and Wi-Fi STA.


1. Multi-Interface Architecture & Ownership

Interface IDHardware / SoCDefault PriorityOwnershipOpt-In Build Flag
eth_spiWIZnet W5500 SPI Ethernet (all 4 SoCs)100HAL_OWNER_OSEnabled on 8+ MiB / --enable-w5500
eth_rmiiInternal EMAC + LAN8720 / IP101 (Classic esp32)90HAL_OWNER_OS--enable-rmii (esp32 only)
usb_ncmTinyUSB CDC-NCM Virtual NIC (esp32s3 USB-OTG)80HAL_OWNER_OS--usb-mode ncm (esp32s3 only)
wifi_staOnboard Wi-Fi 4 / Wi-Fi 6 STA50HAL_OWNER_OSBuilt-in
ppp_uartUART PPP Cellular / Serial Dial-Up20HAL_OWNER_OSOpt-in

Because hal.net is HAL_OWNER_OS, calling stop_app() or soft-resetting MicroPython (hal.wired_reset_app_handles()) never drops your Ethernet or USB-NCM link. Your LAN Bridge (:8266) and Web Dashboard stay reachable while you iterate on apps.


2. Attaching a W5500 SPI Ethernet Module (or Overlay)

import hal

# Attach M5Stack LAN Base / PoE Module via shared SPI bus (pin-guarded!)
hal.net.attach_eth("w5500", port="mbus", spi_host=1, cs=5, irq=35, rst=33, dhcp=True)

print("Active route:", hal.net.active_route())  # -> "eth_spi"
print("Interfaces:", hal.net.interfaces())

Or use the declarative overlay in /etc/overlays.d/ / built-in registry:

import pylotos.overlays as overlays

overlays.apply_overlay("m5stack_lan_w5500", persist=True)

3. Classic ESP32 RMII EMAC (LAN8720 / IP101) & ESP32-S3 USB-NCM

# Classic ESP32 board with RMII PHY (built with `--enable-rmii`)
hal.net.attach_eth("lan8720", mdc=23, mdio=18, phy_addr=1, rst=-1, dhcp=True)

# ESP32-S3 board built with `--usb-mode ncm` (plug-and-play USB Ethernet!)
hal.net.attach_usb_ncm()

4. Hot-Plug Failover, Static IP & Locking the :8266 Bridge

When Ethernet is unplugged (ETHERNET_EVENT_DISCONNECTED), hal_net_wired.c automatically recomputes the highest-priority active interface and calls esp_netif_set_default_netif(), failing over to usb_ncm or wifi_sta with zero user-space polling.

# Tune route priority dynamically
hal.net.set_priority("eth_spi", 120)
hal.net.set_priority("wifi_sta", 40)

# Assign static IPv4 on industrial VLANs
hal.net.set_static_ip("eth_spi", "10.20.30.40", "255.255.255.0", "10.20.30.1")

# Security hardening: restrict LAN AI MCP Bridge & OTA Push to wired NICs only
hal.net.set_bridge_ifaces(["eth_spi", "eth_rmii", "usb_ncm"])

5. Run the Interactive Simulator Example

pylotos-sim examples/ethernet_failover_and_usb_ncm.py --board m5stack_cores3

See the full runnable source in examples/ethernet_failover_and_usb_ncm.py.