-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ethernet Static IP Fails #5733
Comments
Very strange. I received a notification from a user that looked like a response to this issue, however there is no response here. the user wrote this: Try this: // Configures static IP address First, calling ETH.config before ETH.begin causes a device panic. This has been reported on Github before but it has not been fixed: Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Core 1 register dump: Backtrace:0x400d9770:0x3ffb26a00x400d82b6:0x3ffb26e0 0x4017abd2:0x3ffb2700 0x400d422b:0x3ffb2750 0x4017917e:0x3ffb2820 Exception Cause: Not found 0x400d9773: esp_netif_dhcpc_stop at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_netif/lwip/esp_netif_lwip.c:1047 So I moved the call to after ETH.begin and it fails. |
@weswitt , could you please set the "Core Debug Level" option to "Verbose" and report back the messages in both cases (config() before begin() and vice-versa)? |
setting the core debug level to 5 changes the timing and i get a different behavior. it will succeed always with a good/expected set of messages. with the debug level set to zero the static ip will work sometimes and fail other times. even when it works i get the message: "E (4906) esp_netif_handlers: invalid static ip". with the core debug level set to zero the behavior is very flakey. in looking at the code paths for ETH.config it seems that calling it before ETH.begin is not supported. it expects things to be setup and will panic. it looks like it ends up referencing a null pointer that is expected to be valid. |
It sounds like the sketch may have to wait for a while after begin(), before calling config (), is it right? If a delay(1000) is used between them, it works? I guess that some SPI communication is going on in a separated task in paralell with the sketch task. It could be a racing condition. |
thanks @SuGlider . your analysis seems to be correct. i added a 1 second delay after calling ETH.begin and it now seems to be reliable and i do not get the "invalid static ip" message. |
Anyway, it means that some RTOS lock is necessary in the code in order to make config() wait until begin() is done. Feel free to send a PR to fix Arduino Ethernet Library, it f you want to do so. |
I was able to reproduce this issue using an ESP32-Ethernet-Kit_A_V1.2 board (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-ethernet-kit.html) I've got 2 possible error messages:
Sketch used to reproduce both issues: #include <ETH.h>
#define ETH_ADDR 1
#define ETH_POWER_PIN 5
#define ETH_TYPE ETH_PHY_IP101
static bool eth_connected = false;
void WiFiEvent(WiFiEvent_t event)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
//set eth hostname here
ETH.setHostname("esp32-ethernet");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.print("ETH MAC: ");
Serial.print(ETH.macAddress());
Serial.print(", IPv4: ");
Serial.print(ETH.localIP());
if (ETH.fullDuplex()) {
Serial.print(", FULL_DUPLEX");
}
Serial.print(", ");
Serial.print(ETH.linkSpeed());
Serial.println("Mbps");
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char * host, uint16_t port)
{
Serial.print("\nconnecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
}
void setup()
{
Serial.begin(115200);
WiFi.onEvent(WiFiEvent);
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_TYPE);
// In order to see the error messages, please set Debug Level to "Error"
// keeping <delay(0)> will produce this error message and it will not set Static IP: [ 1767][E][ETH.cpp:397] config(): STA IP could not be configured! Error: 20487
// commetting out <delay(0)> will produce this error message and it will set static IP OK: E (3499) esp_netif_handlers: invalid static ip
delay(0);
ETH.config(
IPAddress(192, 168, 1, 250), // Own IP Addr
IPAddress(192, 168, 1, 1), // Gateway
IPAddress(255, 255, 255, 0), // Netmask
IPAddress(192, 168, 1, 1), // DNS1
IPAddress(8, 8, 8, 8)); // DNS2
}
void loop()
{
if (eth_connected) {
testClient("google.com", 80);
Serial.print("My IP: ");
Serial.print(ETH.localIP());
Serial.println();
}
delay(30000);
} |
Summary Only affects ETH (not WiFi) This PR solves #5733 by allowing the DHCP IDF server to complete its tasks and only then it sets a static IP. This also solves another related failure reported in this issue (#5733 (comment)). fix #5733 Impact Adds a delay in order to wait for DHCP to actually terminate before setting the static IP configuration in ETH.
Using Arduino ESP32 v2.0.0 and Arduino IDE v1.8.16. Board is a WESP32 with the ETH_PHY_RTL8201 chip.
I cannot get static IP to work -- very simple code below. The network initializes just fine but I get a DHCP address. I tried calling ETH.config before ETH.begin but that results in the system crashing. Is there a way to get a static IP to work?
The text was updated successfully, but these errors were encountered: