Skip to content
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

ETH static IP configuration doesn't work #9673

Closed
1 task done
JAndrassy opened this issue May 23, 2024 · 11 comments
Closed
1 task done

ETH static IP configuration doesn't work #9673

JAndrassy opened this issue May 23, 2024 · 11 comments
Assignees
Labels
Area: WiFi Issue related to WiFi Status: Awaiting triage Issue is waiting for triage

Comments

@JAndrassy
Copy link
Contributor

JAndrassy commented May 23, 2024

Board

ESP32 Dev module

Device Description

Espressif dev module

Hardware Configuration

W5500 wired on default SPI pins

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Linux

Flash frequency

40

PSRAM enabled

yes

Upload speed

any

Description

ETH.config doesn't set static IP configuration, because of

  if (_esp_netif == NULL) {
    return false;
  }

in NetworkInterface.config

Sketch

#define ETH_PHY_TYPE        ETH_PHY_W5500
#define ETH_PHY_ADDR        -1
#define ETH_PHY_CS           5
#define ETH_PHY_IRQ         -1
#define ETH_PHY_RST         -1
#define ETH_PHY_SPI         SPI

#include <ETH.h>

void setup() {

  Serial.begin(115200);
  delay(500);

  SPI.begin();

  IPAddress ip(192, 168, 1, 177);
  IPAddress gw(192, 168, 1, 1);
  IPAddress dns(192, 168, 1, 1);
  IPAddress mask(255, 255, 255, 0);

  ETH.config(ip, dns, gw, mask);
  ETH.begin();
  while (!ETH.hasIP()) {
    Serial.print('.');
    delay(1000);
  }
  if (ip != ETH.localIP()) {
    Serial.println("ERROR: Static IP was not used.");
  }

 }

void loop() {

}

Debug Message

ERROR: Static IP was not used.

Other Steps to Reproduce

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@JAndrassy JAndrassy added the Status: Awaiting triage Issue is waiting for triage label May 23, 2024
@VojtechBartoska VojtechBartoska added the Area: WiFi Issue related to WiFi label May 23, 2024
@JAndrassy
Copy link
Contributor Author

#9435

@me-no-dev
Copy link
Member

AFTER begin ;) there is nothing to set the address to. WiFi works differently in this regard

@me-no-dev me-no-dev closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@JAndrassy
Copy link
Contributor Author

so static IP can be used only if begin() with DHCP is executed first?

@me-no-dev
Copy link
Member

me-no-dev commented May 26, 2024

static IP can only be used if you begin the interface. DHCP comes much later (if you make the calls one after another) and DHCP/StaticIP needs the netif initialized (which happens in begin)

@JAndrassy
Copy link
Contributor Author

it doesn't work

#define ETH_PHY_TYPE        ETH_PHY_W5500
#define ETH_PHY_ADDR        -1
#define ETH_PHY_CS           5
#define ETH_PHY_IRQ         -1
#define ETH_PHY_RST         -1
#define ETH_PHY_SPI         SPI

#include <ETH.h>

void setup() {

  Serial.begin(115200);
  delay(500);

  SPI.begin();

  IPAddress ip(192, 168, 1, 177);
  IPAddress gw(192, 168, 1, 1);
  IPAddress dns(192, 168, 1, 1);
  IPAddress mask(255, 255, 255, 0);

  ETH.begin();
  ETH.config(ip, dns, gw, mask);

  Serial.print("Attempt to connect to port 80 on ");
  Serial.println(gw);
  NetworkClient client;
  if (client.connect(gw, 80)) {
    Serial.println("\t...success");
  } else {
    Serial.println("\t...ERROR");
  }
  client.stop();
  Serial.println();


 }

void loop() {
}
Attempt to connect to port 80 on 192.168.1.1
[   629][E][NetworkClient.cpp:242] connect(): connect on fd 48, errno: 118, "Host is unreachable"
	...ERROR

@me-no-dev
Copy link
Member

@JAndrassy
Copy link
Contributor Author

sorry I don't know from where did I copy that line into the minimal test, but I had the error in the big test sketch so fixing the ordering doesn't help.

IP Address: 192.168.1.177
gateway IP Address: 192.168.1.1
subnet IP mask: 255.255.255.0

Attempt to connect to port 80 on 192.168.1.1
[  9618][E][NetworkClient.cpp:242] connect(): connect on fd 48, errno: 118, "Host is unreachable"
	...ERROR

@me-no-dev
Copy link
Member

  IPAddress ip(192, 168, 254, 8);
  IPAddress gw(192, 168, 254, 1);
  IPAddress mask(255, 255, 255, 0);
  IPAddress dns(192, 168, 254, 3);
  SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
  ETH.begin(ETH_TYPE, ETH_ADDR, ETH_CS, ETH_IRQ, ETH_RST, SPI);
  ETH.config(ip, gw, mask, dns);
============
Network Info
============
*eth0: <UP,100M,FULL_DUPLEX,AUTO,ADDR:0x1> (DHCPC_OFF,GARP,IP_MOD)
      ether 32:C6:F7:F4:2F:8C
      inet 192.168.254.8 netmask 255.255.255.0 broadcast 192.168.254.255
      gateway 192.168.254.1 dns 192.168.254.3

============
[  3230][D][NetworkManager.cpp:83] hostByName(): Clearing DNS cache
[ 10236][E][NetworkManager.cpp:130] hostByName(): DNS Failed for 'google.com' with error '-54'
[ 13246][I][NetworkClient.cpp:253] connect(): select returned due to timeout 3000 ms for fd 48
Connection Failed
[ 33269][D][NetworkManager.cpp:123] hostByName(): DNS found IPv4 142.250.187.142
Connection Success

IP was correctly assigned and was able to connect to google, though the first attempt failed with DNS error, but second attempt was success.
Can you try a second connect?

@JAndrassy
Copy link
Contributor Author

JAndrassy commented May 27, 2024

I found this #5733 in ETH.cpp mentioned at the end of begin for internal MAC

  // holds a few milliseconds to let DHCP start and enter into a good state
  // FIX ME -- addresses issue https://github.com/espressif/arduino-esp32/issues/5733
  delay(50);

@JAndrassy
Copy link
Contributor Author

JAndrassy commented May 27, 2024

this works

  ETH.begin();
  while (!ETH.linkUp()) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println();
  ETH.config(ip, gw, mask, dns);

maybe begin should wait for linkUP

@me-no-dev
Copy link
Member

waiting in libs should be set to minimum. I'll try to find another solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

3 participants