I am working on a project that requires the use of a static ip via the ethernet connection of my ESP32-WROOM-32E on OLIMEX ESP32-PoE-ISO-Ind shield. I have already tried several codes but have never been able to assign a static address. Below is the code I am using and the serial I receive.
CODE
#include <Ethernet.h>
// Imposta l'indirizzo IP statico
IPAddress ip(192, 168, 3, 12); // Modifica con il tuo indirizzo IP desiderato
IPAddress gateway(192, 168, 3, 1); // Gateway IP
IPAddress subnet(255, 255, 255, 0); // Subnet mask
// Imposta il MAC address del tuo modulo Ethernet
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Modifica con il tuo MAC address
void setup() {
Serial.begin(115200);
Serial.println("Inizializzazione...");
// Inizializza la connessione Ethernet con l'indirizzo IP statico
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("Connessione in corso...");
// Attendere la connessione per un massimo di 10 secondi
int timeout = 10000;
unsigned long startTime = millis();
while (Ethernet.localIP() == IPAddress(0,0,0,0)) {
if (millis() - startTime >= timeout) {
Serial.println("Timeout durante la connessione.");
break;
}
delay(1000);
}
// Se connesso, stampa l'indirizzo IP assegnato
if (Ethernet.localIP() != IPAddress(0,0,0,0)) {
Serial.print("Connessione stabilita. Indirizzo IP: ");
Serial.println(Ethernet.localIP());
} else {
Serial.println("Connessione non riuscita.");
}
}
void loop() {
}
SERIAL OUTPUT
Inizializzazione...
Connessione in corso...
Connessione stabilita. Indirizzo IP: 255.255.255.255
The connection is working because using DHCP everything works correctly, however, I do not understand why you cannot assign a static ip address by receiving on the serial that the ip has been assigned to 255.255.255.255
I already tried using another library “ETH.h” as well, but it didn’t work with that either. What I expect is that by passing as parameters to the begin function of the ethernet ip, gateway and netmask we will be able to connect with the desired ip to the network