class LAN – control an Ethernet module — MicroPython latest documentation (original) (raw)

This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

This class allows you to control the Ethernet interface. The PHY hardware type is board-specific.

Example usage, for a board with built-in LAN support:

import network nic = network.LAN(0) print(nic.ipconfig("addr4"))

now use socket as usual

...

Constructors

class network.LAN(id, *, phy_type=<board_default>, phy_addr=<board_default>, ref_clk_mode=<board_default>)

Create a LAN driver object, initialise the LAN module using the given PHY driver name, and return the LAN object.

Arguments are:

For example, with the Seeed Arch Mix board you can use:

nic = LAN(0, phy_type=LAN.PHY_LAN8720, phy_addr=1, ref_clk_mode=Pin.IN)

Methods

LAN.active([_state_])

With a parameter, it sets the interface active if state is true, otherwise it sets it inactive. Without a parameter, it returns the state.

LAN.isconnected()

Returns True if the physical Ethernet link is connected and up. Returns False otherwise.

LAN.status()

Returns the LAN status.

LAN.ifconfig([(ip, subnet, gateway, _dns)_])

Get/set IP address, subnet mask, gateway and DNS.

When called with no arguments, this method returns a 4-tuple with the above information.

To set the above values, pass a 4-tuple with the required information. For example:

nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))

LAN.config(config_parameters)

Sets or gets parameters of the LAN interface. The only parameter that can be retrieved is the MAC address, using:

The parameters that can be set are:

Specific LAN class implementations

On the mimxrt port, suitable values for the phy_type constructor argument are:PHY_KSZ8081, PHY_DP83825, PHY_DP83848, PHY_LAN8720, PHY_RTL8211F.