Skip to content

Ethernet

Ethernet connection to a LAN network.

This document describes how to configure and use Ethernet functionality in Spectoda devices.

Ethernet is configured through a JSON object in Controller config. Here is a complete example:

{
"ethernet": {
"variant": "LAN8720",
"type": "LAN8720",
"ip": "20.0.0.4",
"gateway": "20.0.0.1",
"mask": "255.255.255.0",
"dns": "8.8.8.8",
"hostname": "spectoda"
}
}
ParameterTypeDescriptionDefault value
enablebooleanEnables or disables Ethernet functionalitytrue if ethernet is defined in JSON
ipstringStatic IP address of the deviceDHCP if not set
gatewaystringGateway IP addressRequired when using a static IP
maskstringNetwork maskRequired when using a static IP
dnsstringDNS server IP addressOptional
hostnamestringDevice name on the networkOptional

Predefined variants

Use the variant parameter to select a predefined hardware configuration:

VariantDescription
LAN8720Standard LAN8720 configuration
OLIMEXPOEConfiguration for the Olimex PoE board
OLIMEXPOE2Configuration for the Olimex PoE 2 board

Ethernet PHY type

Use the type parameter to specify the Ethernet PHY chip:

TypeDescription
IP101IP101 PHY
RTL8201RTL8201 PHY
LAN8720LAN8720 PHY
DP83848DP83848 PHY
KSZ8041KSZ8041 PHY
KSZ8081KSZ8081 PHY

These parameters allow fine-tuning of the Ethernet hardware configuration:

ParameterTypeDescriptionDefault valueValid values
phydetnumberPHY address detection. Defines the PHY address used for communication.0-1 (auto-detection), 0-31
phymdcnumberPHY MDC pin. Management Data Clock pin for the MDIO interface.23GPIO 0-39
phymdionumberPHY MDIO pin. Management Data Input/Output pin for the MDIO interface.18GPIO 0-39
phyennumberPHY Enable pin. Used to enable or disable the PHY chip.12GPIO 0-39
phyrstnumberPHY Reset pin. Hardware reset pin for the PHY chip.-1-1 (disabled), GPIO 0-39
rmiipinnumberRMII Clock pin. Defines the GPIO used for the RMII clock signal.00 (EMAC_APPL_CLK_OUT_GPIO), 16-17
rmiimodenumberRMII Clock Mode. Configures the RMII clock source.20 (GPIO0_IN), 1 (GPIO0_OUT), 2 (EMAC_CLK_OUT), 3 (EMAC_CLK_OUT_180)
timeoutnumberSW Reset Timeout in milliseconds. Maximum wait time for PHY reset.1000100-10000

Important implementation details:

  1. PHY address detection (phydet)
    • Use -1 for automatic detection.
    • Values 0-31 specify a fixed PHY address.
    • Most configurations work with address 0.
  2. Clock configuration (rmiimode)
    • EMAC_CLK_OUT (2): standard clock output mode.
    • EMAC_CLK_OUT_180 (3): clock signal shifted by 180 degrees.
    • GPIO0_IN/OUT (0, 1): external clock source modes.
  3. Pin configuration
    • All GPIO pins must be valid ESP32 pins (0-39).
    • Avoid pins already used by other functions.
    • Some pins may be reserved on specific ESP32 modules.
  4. Reset behaviour
    • When phyrst is set to -1, software reset is used.
    • Hardware reset through phyrst is more reliable, but requires an additional GPIO.
  5. Timing
    • The system waits 10 ms after enabling PHY before continuing initialization.
    • Adjust timeout according to the PHY chip specifications.
    • Longer timeouts are more reliable, but increase boot time.

Config examples

Standard LAN8720 config:

{
"ethernet": {
"phydet": 0,
"phymdc": 23,
"phymdio": 18,
"phyen": 12,
"phyrst": -1,
"rmiimode": 2,
"rmiipin": 0,
"timeout": 1000
}
}

Olimex POE config:

{
"ethernet": {
"phydet": 0,
"phymdc": 23,
"phymdio": 18,
"phyen": 12,
"phyrst": -1,
"rmiimode": 2,
"rmiipin": 17,
"timeout": 1000
}
}

Possible error codes:

Error codeDescriptionPossible solution
50768234Invalid Ethernet typeCheck that the specified type is supported
45553478Ethernet type is not a stringMake sure type is a string
56927834IP address is not a stringMake sure ip is a string
23074945Gateway IP address is not a stringMake sure gateway is a string
26347089Netmask IP address is not a stringMake sure mask is a string
62507839DNS IP address is not a stringMake sure dns is a string
10435793Hostname is not a stringMake sure hostname is a string
29683748Failed to create ESP32 Ethernet MACCheck the hardware connection
23498792Failed to create Ethernet PHYCheck the PHY configuration
95273483Failed to install Ethernet driverCheck system resources
15694378Failed to register Ethernet event handlerCheck system resources
31729483Failed to register IP event handlerCheck system resources
92657834Failed to attach Ethernet driver to the TCP/IP stackCheck system configuration
23148734Failed to set network interface hostnameCheck hostname validity
69853473Failed to stop DHCP serverCheck network configuration
68239473Failed to stop DHCP clientCheck network configuration

The Ethernet interface generates warning codes for the following events:

Warning codeDescriptionAdditional information
62537809Ethernet Link UpPhysical connection established
59634873Ethernet Link DownPhysical connection lost
95624383Ethernet StartedInterface initialized successfully
62579839Ethernet StoppedInterface stopped
69278533Ethernet Got IP AddressIP configuration obtained

When an IP address is obtained, the system logs information about IP, Gateway and Netmask.

  1. When using static IP configuration, all three parameters (ip, gateway and mask) must be provided.
  2. The PHY Enable pin is set to HIGH during initialization.
  3. The system waits 10 ms after enabling PHY before continuing initialization.
  4. DHCP is used by default if no static IP configuration is provided.