- This topic has 2 replies, 2 voices, and was last updated 7 months, 1 week ago by .
- 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
Thanks for the reply, I’ll try using the library #include <ETH.h>.
More
Just like a well-organized workbench, this website uses cookies to function properly and efficiently.
🛠️ The Essentials (Necessary): Some cookies are categorized as necessary and are stored on your browser because they are critical for the basic working of the site.
📊 The Analytics (Third-party): We also use third-party cookies to help us analyze traffic and understand which projects you like the most. These are stored only if you give us the green light.
You can choose to opt-out, but keep in mind that disabling them might make the site experience a bit less "smooth".
| Cookie | Duration | Description |
|---|---|---|
| cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
| cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
| cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
| cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
| cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
| viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
