ESP32-POE-ISO not able to set static IP

Started by alborz, June 12, 2019, 11:10:57 AM

Previous topic - Next topic

alborz

Hi,
I am using platform.io with arduino to program ESP32-POE-ISO board and trying to set an static ip address for the ethernet.

If I run the example provided by you:

// This sketch shows the Ethernet event usage
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_PHY_POWER 12

#include <ETH.h>


static bool eth_connected = false;

void WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      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");
      eth_connected = true;
      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 testClient(const char * host, uint16_t port)
{
  Serial.print("\nconnecting to ");
  Serial.println(host);

  WiFiClient client;
  if (!client.connect(host, port)) {
    Serial.println("connection failed");
    return;
  }
  client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
  while (client.connected() && !client.available());
  while (client.available()) {
    Serial.write(client.read());
  }

  Serial.println("closing connection\n");
  client.stop();
}

void setup()
{
  Serial.begin(115200);
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
 
}


void loop()
{
  if (eth_connected) {
    testClient("google.com", 80);
   
    Serial.println(ETH.localIP());      //192.168.1.100
    Serial.println(ETH.gatewayIP());    //192.168.1.1
    Serial.println(ETH.subnetMask());   //255.255.255.0
    Serial.println(ETH.dnsIP());        //192.168.1.1
  }
  delay(10000);

}


The example acquire IP and runs fine, it prints the following addresses:

Serial.println(ETH.localIP());      //192.168.1.100
Serial.println(ETH.gatewayIP());    //192.168.1.1
Serial.println(ETH.subnetMask());   //255.255.255.0
Serial.println(ETH.dnsIP());        //192.168.1.1

and it is able to communicate to google.com.

But I would like to change the IP statically. As an example to 192.168.1.101
I do that by adding the following line right after ETH.begin().

ETH.begin();

ETH.config(IPAddress(192, 168, 1, 101),IPAddress(192, 168, 1, 1),IPAddress(255, 255, 255, 0),IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1));


It still works fine, and I get the following output, and I can talk to google.com

ETH MAC: 30:AE:A4:9F:F7:A7, IPv4: 192.168.1.101, FULL_DUPLEX, 100Mbps


But as soon as I change the IP to something like 192.168.0.101 then it does not work anymore.

TH Started
ETH MAC: 30:AE:A4:9F:F7:A7, IPv4: 192.168.0.101, FULL_DUPLEX, 100Mbps
ETH MAC: 30:AE:A4:9F:F7:A7, IPv4: 192.168.0.101, FULL_DUPLEX, 100Mbps

connecting to google.com
[E][WiFiGeneric.cpp:658] hostByName(): DNS Failed for google.com
connection failed


Can anyone explain why this is happening?
Why does it work with 192.168.1.101 but not with 192.168.0.101?

PeteW



LubOlimex

The problem is not in the ESP32-POE-ISO. When you change the IP from x.x.Y.x to x.x.Z.x you also need to change the rest of the settings of the network (subnet mask, etc). Also the DHCP in your network equipment might be configured to give IP address only in specific subnet mask (e.g. only addresses 192.168.1.x and not addresses from sub-net network 192.168.0.x).
Technical support and documentation manager at Olimex

alborz

The problem was on my side, the router was configured faulty.
Thanks anyway