Hello!
I am using Arduino IDE 2.3.4 and an ARDUINO UNO R4 WiFi with the Ethernet Shield. I use the example from https://github.com/wolfSSL/wolfMQTT/blo … client.ino slope game
For the Ethernet connection I modified the setup:
void setup() {
Serial.begin(115200);
Serial.println("### Ethernet & MQTT Debugging ###");Serial.println("[Ethernet] Initialisierung...");
Ethernet.begin(mac);
delay(1000);if (Ethernet.localIP() == INADDR_NONE) {
Serial.println("[Ethernet] DHCP fehlgeschlagen, versuche statische IP...");
Ethernet.begin(mac, ip, dns, gateway, subnet);
}Serial.print("[Ethernet] Lokale IP-Adresse: ");
Serial.println(Ethernet.localIP());
}For the settings:
#include <wolfMQTT.h>
#include <Ethernet.h>
#include <wolfssl.h>
#include <wolfssl/version.h>// MAC-Adresse für das Ethernet-Modul
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 9); // Statische IP-Adresse
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192, 168, 0, 1);/* Konfiguration */
#define DEFAULT_MQTT_HOST "192.168.0.4"
#define DEFAULT_CMD_TIMEOUT_MS 30000
#define DEFAULT_CON_TIMEOUT_MS 5000
#define DEFAULT_MQTT_QOS MQTT_QOS_0
#define DEFAULT_KEEP_ALIVE_SEC 30
#define DEFAULT_CLIENT_ID "WolfMQTTClient"
#define WOLFMQTT_TOPIC_NAME "wfs"
#define DEFAULT_TOPIC_NAME WOLFMQTT_TOPIC_NAME "/status"#define MAX_BUFFER_SIZE 1024
#define TEST_MESSAGE "test"static word16 mPort = 1883;
static const char* mHost = DEFAULT_MQTT_HOST;
static int mStopRead = 0;It connects to the Ethernet and gets an IP-Number view DHCP and it also connects to the mosquito Broker.
But here it comes back with rc=1 which is unknown:
rc = MqttClient_NetConnect(&client, mHost, mPort, DEFAULT_CON_TIMEOUT_MS, 0, NULL);
Serial.print("[MQTT] Socket Connect: ");
Serial.println(rc);I can reach the mosquito with 2 other clients with no problem.
What could be the reason for this?
Hey! I actually ran into a similar issue when trying WolfMQTT on the UNO R4 WiFi. The rc=1 result usually points to a connection failure at the socket layer rather than an MQTT protocol issue. In my case, it was related to how the Ethernet shield handled DNS or socket timeouts.
You might try hardcoding the broker’s IP instead of the hostname (even if it looks the same), and double-check that port 1883 is open on your local network. Also, make sure the Ethernet.begin() call isn’t overwriting network settings after DHCP fails. Adding a small delay before calling MqttClient_NetConnect() helped stabilize my connection, too.