Dhcp not working on esp32 using arduino

Below is the code I used

#include <SPI.h>
#include <WiFi.h>
//#include <EthernetENC.h>
#include <UIPEthernet.h>

const char* ssid = "hkiot";
const char* password = "10818117A*";

byte mac[] = { 0x1d, 0x0c, 0xd8, 0x0c, 0x55, 0xee };

char server[] = "www.google.com";    // name address for Google (using DNS)
#define CLIENT_ID       "JEZIEL_78233"

IPAddress ip(192, 168, 3, 177);
IPAddress myDns(192, 168, 3, 1);

void setup() {
  Serial.begin(115200);
  //setup_wifi();
  SPI.begin(25, 32, 33, 27);
  Ethernet.init(27);
  Serial.println(Ethernet.hardwareStatus());
  Serial.println(Ethernet.linkStatus());
  Serial.println("Initialize Ethernet with DHCP:");
  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 shißeld 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());
  }
}

void loop() {
}

This is the result of the above.

rst:0x1 (POWERON_RESET),boot:0x12 (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:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
10
1
Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP

This circuit is a simplified version of only the Ethernet circuit in which enc28j60 is used in the circuit I made.

The code and circuit above worked normally once before.

I can't find the cause, so I'd like to ask for your help. thank you

Looks like hardwareStatus() returned 10 and linkStatus() returned 1. What I would do is examine the UIPEthernet library to see what those two values mean.

Sniff on the network and post what packets you see there.

A good idea is also to set the log level to LOG_DEBUG_V1. Then you see on the serial what actually happens and what the last state is the DHCP client reaches.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.