Good day, I want to use w5500 lite ethernet module with mqtt using esp32. However, I get the error Could not configure Ethernet using DHCP. The code and module links I used are attached.
#include <Ethernet.h>
#include <PubSubClient.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient net;
PubSubClient client;
unsigned long lastMillis = 0;
void connect() {
Serial.print("connecting...");
while (!client.connect("arduino32")) {
}
Serial.println("\nconnected!");
client.subscribe("/hello");
// client.unsubscribe("/hello");
}
void callback(char* topic, byte* payload, unsigned int length) {
}
void setup() {
Serial.begin(57600);
Serial.println("Start Setup");
if (Ethernet.begin(mac)==0){
Serial.println("Failed to configure Ethernet using DHCP");
for(;;)
;
}
Ethernet.begin(mac, Ethernet.localIP());
Serial.println("Start MQTT");
client.setKeepAlive(90);
client.setClient(net);
client.setServer("xx.xxx.xxx.xxx", 1883);
client.setCallback(callback);
connect();
}
void loop() {
if (!client.connected()) {
connect();
}
// publish a message roughly every second.
if (millis() - lastMillis >5000) {
lastMillis = millis();
client.publish("/hello", "world");
}
client.loop();
}