class LAN – control an Ethernet interface¶
The LAN class drives the MCU’s on-chip Ethernet MAC against
an external RMII PHY. The PHY type, MDIO address and pinout are all
board-specific; sensible defaults are baked into each OpenMV board so
the constructor normally takes no arguments.
Available on:
OpenMV Cam N6 (STM32 port) – default PHY
PHY_LAN8742.Arduino Portenta H7 (STM32 port) – default PHY
PHY_LAN8742.OpenMV Cam RT1062 (mimxrt port) – default PHY
PHY_KSZ8081.
Example usage:
import network
nic = network.LAN()
nic.active(True)
while not nic.isconnected():
pass
print(nic.ipconfig("addr4"))
Constructors¶
- class network.LAN(id: int = 0, *, phy_type: int | None = None, phy_addr: int | None = None, ref_clk_mode: int | None = None) None¶
Construct a
LANinterface object. All arguments afteridare keyword-only.idselects the Ethernet port on boards that expose more than one (mimxrt port:0= ENET,1= ENET_1). Ignored on STM32 boards, which only have a single MAC.phy_typeselects the PHY driver (one of thePHY_*constants below). PassNone(the default) to use the PHY wired to the OpenMV board.phy_addris the MDIO address of the PHY on the management bus. PassNone(the default) to use the board’s wired value.ref_clk_mode(mimxrt only) selects whether the RMII reference clock is driven by the MAC (OUT) or by the PHY (IN). Ignored on STM32 boards.Methods¶
- active(is_active: bool | None = None) bool¶
Bring the Ethernet MAC up or down.
With no argument, return the current PHY link status as a truthy/falsy integer – see
status()for the full set of encoded values.active(True)starts the MAC and PHY, kicks off auto-negotiation, and brings the lwIP netif up. Link-up itself may take a moment to complete – pollisconnected()if you need to block until the link is fully ready. All other methods (ipconfig(),config(), …) require the interface to be active.active(False)stops the MAC and tears down the netif.
- isconnected() bool¶
Return
Truewhen the PHY has negotiated link-up and the interface is in the fully-up state (link status value3).
- status() int¶
Return the raw PHY link status as an integer:
0– link down.1– link up (PHY only, IP stack not yet ready).2– transitioning.3– link up and the IP stack has finished bringing the interface up.
- ifconfig(config: Tuple[str, str, str, str] | None = None) Tuple[str, str, str, str] | None¶
Get or set IPv4 interface parameters as a 4-tuple of
(ip, subnet, gateway, dns)dotted-quad strings.Note
Prefer
ipconfig()for new code:nic.ipconfig(addr4="192.168.0.4/24", gw4="192.168.0.1") network.ipconfig(dns="8.8.8.8")
- ipconfig(param: str) Any¶
- ipconfig(**kwargs: Any) None
Get or set IPv4 / IPv6 interface parameters. Behaves the same as
AbstractNIC.ipconfig()– see that method for the full list of supported parameter names (dhcp4,addr4,gw4,autoconf6,addr6, …).
- config(param: str) Any¶
- config(**kwargs: Any) None
Get or set Ethernet-specific interface parameters.
With a single positional string argument, return the value of that parameter:
"mac"– the interface MAC address as a 6-bytebytesobject.
With keyword arguments, set one or more parameters:
trace=<int>– enable lwIP tracing. Bit-field:2traces TX,4traces RX,8enables full tracing.low_power=<bool>– enable or disable the PHY’s IEEE 802.3az (Energy Efficient Ethernet) low-power mode.
Constants¶
- PHY_LAN8742: int¶
Microchip LAN8742A 10/100 Ethernet PHY. STM32 port only; default on the OpenMV Cam N6 and Arduino Portenta H7.
- PHY_DP83848: int¶
Texas Instruments DP83848 10/100 Ethernet PHY. Available on both STM32 and mimxrt ports.
- PHY_DP83825: int¶
Texas Instruments DP83825 10/100 Ethernet PHY. Available on both STM32 and mimxrt ports.