You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the "ArduinoMqttClient" library (version 0.1.7) to connect to an MQTT broker. However, I have encountered an issue where the mqttClient.connected() function always returns 0, even when the connection to the MQTT broker is active and data is being sent.
Environment:
Arduino board: MKR1010
Code:
#include"wifi.h"
#include"mqtt.h"
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);
constlong interval = 15000;
unsignedlong previousMillis = 0;
voidsetup() {
Serial.begin(9600);
while (!Serial)
connectWifiClient();
connectMqttClient(mqttClient);
postHomeassistantDiscoveryObjects(mqttClient);
}
voidloop() {
Serial.println(mqttClient.connected()); // This always returns 0, despite generateTestData() that actually does send data, so the connection clearly works
mqttClient.poll();
unsignedlong currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
generateTestData(mqttClient);
}
checkWifiConnection();
}
The text was updated successfully, but these errors were encountered:
Okay so I attempted to go ahead and move the clientConnected() function from private to the public space in the "MqttClient.h" file from the library instead, and that functions works just fine...
@Andreasjkoch did that solve the problem for you? I'm seeing a similar issue using Arduino Portenta H7 board in Arduino Portenta Machine Control device, connecting to Azure IOT Hub. mqttClient.connected() always returns 0
Yes it did. For some reason the public function just doesn't work. So just move the line defining clientConnected() in MqttClient.h so that it is inside of public
Hi.
I am using the "ArduinoMqttClient" library (version 0.1.7) to connect to an MQTT broker. However, I have encountered an issue where the
mqttClient.connected()
function always returns 0, even when the connection to the MQTT broker is active and data is being sent.Environment:
Code:
The text was updated successfully, but these errors were encountered: