- This topic has 1 reply, 2 voices, and was last updated 17 minutes ago by .
Viewing 1 reply thread
Viewing 1 reply thread
- You must be logged in to reply to this topic.
Ciao everyone, I have a problem with my prototype. I’d like to implement MQTT over LAN using an ESP32 and a standard W5500 Nano.
The prototype successfully acquires an IP address via DHCP, but MQTT doesn’t work.
The code is very simple and minimal.
I tested the same Ethernet cable with my laptop and I can send MQTT messages without issues.
Any ideas?
#include <SPI.h>
#include <Ethernet.h>
#include <MQTT.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAA};
EthernetClient net;
MQTTClient client;
unsigned long lastMillis = 0;
void connect() {
Serial.print("connecting...");
while (!client.connect("TestEsp")) {
Serial.print(".");
delay(1000);
}
Serial.println("connected!");
client.subscribe("/Test");
}
void messageReceived(String &topic, String &payload) {
Serial.println("incoming: " + topic + " - " + payload);
}
void setup() {
Serial.begin(115200);
Ethernet.init(5); //CS pin
Ethernet.begin(mac);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
client.begin("192.168.1.66", net);
client.onMessage(messageReceived);
connect();
}
void loop() {
client.loop();
if (!client.connected()) {
connect();
}
if (millis() - lastMillis > 5000) {
lastMillis = millis();
client.publish("Node32s", "Test");
}
}
Grazie mille
Hi Zemmo,
There can be various problems, but I think a good way to do that is to change the library to use the native stack of ESP32, and you can prevent any issues with authentication.
You can find more info here.
Could you give us feedback about the result and if the problem continues we are going to look into the problem in depth.
Bye Renzo
More