Skip to content

Getting static IP error, however, static IP seems to be assigned. #6

@arjenv

Description

@arjenv

Hardware: WT32 ETH01
esp32 core: 3+

I tried combining the OTA exampe with the legacy example to assign static IP:

/*
 * BasicOTA example from the ESP32 ArduinoOTA library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <ESPmDNS.h>
#include <ArduinoOTA.h>
#include <MacAddress.h>

//W5500Driver driver;
//ENC28J60Driver driver;
//EMACDriver driver(ETH_PHY_LAN8720);
EMACDriver driver(ETH_PHY_LAN8720, 23,18,16);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };

void setup() {

  IPAddress ip(192, 168, 1, 32);
  IPAddress gw(192, 168, 1, 254);
  IPAddress dns(192, 168, 1, 254);
  IPAddress mask(255, 255, 255, 0);

  Serial.begin(115200);
  delay(500);
  while (!Serial);

  Ethernet.init(driver);

  Serial.println("Configuring static IP ");
  Ethernet.begin(mac, ip, dns, gw, mask);
  Serial.println("Just before printethernetstatus");
  printEthernetStatus();
  if (ip != Ethernet.localIP()) {
    Serial.println("ERROR: Static IP was not used.");
    while (true) {
      delay(1);
    }
  }

  ArduinoOTA
    .onStart([]() {
      String type;
      if (ArduinoOTA.getCommand() == U_FLASH) {
        type = "sketch";
      } else {  // U_SPIFFS
        type = "filesystem";
      }

      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
      Serial.println("Start updating " + type);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) {
        Serial.println("Auth Failed");
      } else if (error == OTA_BEGIN_ERROR) {
        Serial.println("Begin Failed");
      } else if (error == OTA_CONNECT_ERROR) {
        Serial.println("Connect Failed");
      } else if (error == OTA_RECEIVE_ERROR) {
        Serial.println("Receive Failed");
      } else if (error == OTA_END_ERROR) {
        Serial.println("End Failed");
      }
    });

  ArduinoOTA.begin();

  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  ArduinoOTA.handle();
}


void printEthernetStatus() {

  byte mac[6];
  Ethernet.MACAddress(mac);
  Serial.print("MAC: ");
  Serial.println(MacAddress(mac));
  if (mac[0] & 1) { // unicast bit is set
    Serial.println("\t is the ordering of the MAC address bytes reversed?");
  }

  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());

  Serial.print("gateway IP Address: ");
  Serial.println(Ethernet.gatewayIP());

  Serial.print("subnet IP mask: ");
  Serial.println(Ethernet.subnetMask());

  Serial.print("DNS server: ");
  IPAddress dns = Ethernet.dnsServerIP();
  if (dns == INADDR_NONE) {
    Serial.println("not set");
  } else {
    Serial.println(dns);
  }
}

I started minicom to read the RS232 output:

Configuring static IP                                                           
E (4506) esp_netif_handlers: invalid static ip                                  
Just before printethernetstatus                                                 
MAC: DE:AD:BE:EF:FE:EF                                                          
IP Address: 192.168.1.32                                                        
gateway IP Address: 192.168.1.254                                               
subnet IP mask: 255.255.255.0                                                   
DNS server: 192.168.1.254                                                       
Ready                                                                           
IP address: 192.168.1.32 

The "E (4506) esp_netif_handlers: invalid static ip " is bugging me. Why is that?
It appears to handle the static IP well in the end.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions