Can't connect directly to ESP using ethernet cable

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Can't connect directly to ESP using ethernet cable

Postby GeorgeFlorian1 » Tue Mar 16, 2021 12:31 pm

Hello.

I have an ESP32-EVB capable of ethernet connection.
I have configured it to be in Station Mode with a given Static IP. I am trying to connect to it using an Ethernet cable from my laptop to the ESP but I can't find it at the given IP address.

How can I connect to the ESP without a router/modem ? I don't think AP Mode is what I need because I don't want to connect to the ESP in order to access it. I want the ESP to be in a network, capable of receiving and sending packets to other devices on that network based on its IP. So basically Station Mode, which, in this case, does not work.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Can't connect directly to ESP using ethernet cable

Postby ESP_Sprite » Wed Mar 17, 2021 2:31 am

Not sure if it's just worded weird, but:
I have configured it to be in Station Mode with a given Static IP. I am trying to connect to it using an Ethernet cable from my laptop to the ESP but I can't find it at the given IP address.
'Station mode' is a WiFi term; are you sure you've not just enabled WiFi and given that interface an IP instead of the Ethernet interface?

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Re: Can't connect directly to ESP using ethernet cable

Postby GeorgeFlorian1 » Wed Mar 24, 2021 11:20 am

ESP_Sprite wrote:
Wed Mar 17, 2021 2:31 am
Not sure if it's just worded weird, but:
I have configured it to be in Station Mode with a given Static IP. I am trying to connect to it using an Ethernet cable from my laptop to the ESP but I can't find it at the given IP address.
'Station mode' is a WiFi term; are you sure you've not just enabled WiFi and given that interface an IP instead of the Ethernet interface?
I suck at networking. I thought that Station is just saying that the device is ready to connect to something and AP when you can connect to it and all of that regardless of WiFi or Ethernet.

The code:

Code: Select all

void WiFiEvent(WiFiEvent_t event) {
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname(host_name);
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      eth_connected = true;
      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");
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case SYSTEM_EVENT_ETH_STOP:
      Serial.println("ETH Stopped");
      eth_connected = false;
      break;
    default:
      break;
  }
}

void EthernetConfig(String x[]){
  if(x[0] == "WiFi") return;
  ETH.begin();
  int ki = 0;
  while(!eth_connected && ki <20) {
    Serial.println("Establishing ETHERNET Connection ... ");
    delay(1000);
    ki++;
  }
  if(!eth_connected) {
    logOutput("(1) Could not access Network ! Trying again...");
    logOutput("Controller will restart in 5 seconds !");
    delay(5000);
    ESP.restart();
  }
  if(x[1] != NULL &&      //Local IP
     x[1].length() != 0 &&
     x[2] != NULL &&      // Gateway
     x[2].length() != 0 &&
     x[3] != NULL &&      // Subnet
     x[3].length() != 0 &&
     x[4] != NULL &&      // DNS
     x[4].length() != 0) {
       local_IP_STA.fromString(x[1]);
       gateway_STA.fromString(x[2]);
       subnet_STA.fromString(x[3]);
       primaryDNS.fromString(x[4]);
       if(!ETH.config(local_IP_STA, gateway_STA, subnet_STA, primaryDNS)) {
         logOutput("Couldn't configure STATIC IP ! Obtaining DHCP IP !");
       }
       delay(50);
  } else {
    logOutput("Obtaining DHCP IP !");
  }
  local_IP_STA = ETH.localIP();
  gateway_STA = ETH.gatewayIP();
  subnet_STA = ETH.subnetMask();
  primaryDNS = ETH.dnsIP();
  logOutput((String)"IP addres: " + local_IP_STA.toString());
  logOutput((String)"Gateway: " + gateway_STA.toString());
  logOutput((String)"Subnet: " + subnet_STA.toString());
  logOutput((String)"DNS: " + primaryDNS.toString());
}

void setup() {
// ...
  WiFi.onEvent(WiFiEvent);
// ...
EthernetConfig(v);

}
I am reading the IP values from a text file into v array, which I then pass to EthernetConfig method.

I am literally connecting the ESP to the PC using an Ethernet cable. There is no network. The devices are not in a network. They are connected to each other.

When this happens, the PC doesn't have any IP address and the ESP only outputs:

Code: Select all

Establishing ETHERNET Connection ... 
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 21 - ETH_START
ETH Started
Establishing ETHERNET Connection ... 
Establishing ETHERNET Connection ... 

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Can't connect directly to ESP using ethernet cable

Postby ESP_Sprite » Thu Mar 25, 2021 1:45 am

If you're directly connected to a PC, your ESP won't get an IP as there is no DHCP server on your (tiny) network. I don't think the ESP software does link-local addresses. It should come good when you plug your ESP into an *actual* network.

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Re: Can't connect directly to ESP using ethernet cable

Postby GeorgeFlorian1 » Fri Mar 26, 2021 2:52 pm

ESP_Sprite wrote:
Thu Mar 25, 2021 1:45 am
If you're directly connected to a PC, your ESP won't get an IP as there is no DHCP server on your (tiny) network. I don't think the ESP software does link-local addresses. It should come good when you plug your ESP into an *actual* network.
So, then, is there no way to assign the ESP32 a Static IP and stop it from getting an IP from the DHCP server, even on Ethernet ?

lbernstone
Posts: 828
Joined: Mon Jul 22, 2019 3:20 pm

Re: Can't connect directly to ESP using ethernet cable

Postby lbernstone » Fri Mar 26, 2021 3:06 pm

If you don't use a hub/switch, you will likely need a crossover cable. Ethernet was designed as a spoke layout, not direct connection. Unless you own a crimper, it is likely cheaper (and more flexible) to just buy a passive 2/4 port switch.
https://en.wikipedia.org/wiki/Crossover_cable

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Can't connect directly to ESP using ethernet cable

Postby chegewara » Fri Mar 26, 2021 3:12 pm

GeorgeFlorian1 wrote:
Fri Mar 26, 2021 2:52 pm
So, then, is there no way to assign the ESP32 a Static IP and stop it from getting an IP from the DHCP server, even on Ethernet ?
It should be possible as long as esp32 is in the same subnet as PC, and to achieve this you have to setup your PC ethernet with static IP or it will be set with local address in 169.254.0.0 subnet. Another thing may be what @lbernstone said about crossover type cable.

Who is online

Users browsing this forum: No registered users and 84 guests