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 ...