ESP32 + ENC28J60 + fixed ip problem

Hello all!
I have a problem with ESP32 with ENC28J60 with fixed IP.
I have a code like this:

#include <SPI.h>
#include <EthernetENC.h>
#include "PubSubClient.h"
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//char server[] = "www.google.com";    // name address for Google (using DNS)
#define CLIENT_ID       "MQTT"
#define INTERVAL        3000 // 3 sec delay between publishing

// Set the static IP address to use if the DHCP fails to assign
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
//#define MYDNS 192,168,1,1
//#define MYGW 192,168,1,1

EthernetClient client;
PubSubClient mqttClient;
long previousMillis;

unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;  // set to false for better speed measurement

const int SensorPin = 4;  // the number of the pushbutton pin
const int ledPin =  2;    // the number of the LED pin

long Czas_1 =0, Czas_2 =0;
long czas = 1000;
int SensorState = 0;
int lastSensorState = 0;

const char* startMessageTopic = "esp32/message"; //temat do wyslania wiadomosci
void setup() {

  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

IPAddress ip(MYIPADDR);
//IPAddress dns(MYDNS);
//IPAddress gw(MYGW);
IPAddress sn(MYIPMASK);
//Ethernet.begin(mac, ip, dns, gw, sn);

  Serial.println("Initialize Ethernet with DHCP:");
  Ethernet.begin(mac, ip, sn);
  delay(1000);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
   // Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
   Serial.println(Ethernet.localIP());
  }
  Ethernet.begin(mac, ip, sn);
  delay(1000);
  Serial.println(Ethernet.localIP());
   //mqttClient.setClient(client);
   //mqttClient.setServer("192.168.1.9", 1883);
   Serial.println(F("MQTT client configured"));
//previousMillis = millis();
  // give the Ethernet shield a second to initialize:
 

  // if you get a connection, report back via serial:

 // beginMicros = micros();
}

void loop() {
  
   SensorState= digitalRead(SensorPin);
  if (SensorState != lastSensorState){
    if (SensorState==HIGH){
     digitalWrite(ledPin, LOW);
   
   mqttClient.publish(startMessageTopic, "Hello from ESP32"); 
    } else {
    // turn LED off
    digitalWrite(ledPin, HIGH);
    
  mqttClient.publish(startMessageTopic, "Hello from ESP32"); 
    }
    
  }  
  lastSensorState=SensorState;
  delay(100);
 
}

I wan to have fixed ip address, but, if i take DHCP i have a address from DHCP, but if i want to have fixed IP, I have IP address when program is in void setup() - in serial port monitor i see string from program.
When program goes to Void loop(), in i lost IP address
image

what is wrong?
can any one help me?

Ethernet is not handled sufficiently in loop(). add Ethernet.maintain();

don't use my EthernetENC library with the ESP32. with ESP32 Arduino platform v 3, use my EthernetESP32 library for enc28j60

Have you tried the example already included in the ESP32 Arduino core?

@cotestatnt that will not work with the ENC28J60

Sorry, my bad.
I confused ENC28J60 with LAN8270

I was still sleepy this morning :sweat_smile:

great, thanks for your help, it works!

What changes did you make to the example?

I tried the EthernetESP32 library, but it keeps resetting:

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4744
load:0x40078000,len:15672
load:0x40080400,len:3152
entry 0x4008059c