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.
Can't connect directly to ESP using ethernet cable
-
- Posts: 160
- Joined: Thu Jan 31, 2019 2:32 pm
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Can't connect directly to ESP using ethernet cable
Not sure if it's just worded weird, but:
'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 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.
-
- Posts: 160
- Joined: Thu Jan 31, 2019 2:32 pm
Re: Can't connect directly to ESP using ethernet cable
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.ESP_Sprite wrote: ↑Wed Mar 17, 2021 2:31 amNot sure if it's just worded weird, but:'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 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.
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 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 ...
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: Can't connect directly to ESP using ethernet cable
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.
-
- Posts: 160
- Joined: Thu Jan 31, 2019 2:32 pm
Re: Can't connect directly to ESP using ethernet cable
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 ?ESP_Sprite wrote: ↑Thu Mar 25, 2021 1:45 amIf 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.
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Can't connect directly to ESP using ethernet cable
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
https://en.wikipedia.org/wiki/Crossover_cable
Re: Can't connect directly to ESP using ethernet cable
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.GeorgeFlorian1 wrote: ↑Fri Mar 26, 2021 2:52 pmSo, 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 ?
Who is online
Users browsing this forum: No registered users and 73 guests