Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

mqttClient.connected() always 0 despite being connected #93

Copy link
Copy link
Open
@Andreasjkoch

Description

@Andreasjkoch
Issue body actions

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:

  • Arduino board: MKR1010

Code:

#include "wifi.h"
#include "mqtt.h"

WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);

const long interval = 15000;
unsigned long previousMillis = 0;

void setup() {
    Serial.begin(9600);
    while (!Serial)
    
    connectWifiClient();
    connectMqttClient(mqttClient);
    postHomeassistantDiscoveryObjects(mqttClient);
}

void loop() {
    Serial.println(mqttClient.connected()); // This always returns 0, despite generateTestData() that actually does send data, so the connection clearly works
    mqttClient.poll();
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
        previousMillis = currentMillis;
        generateTestData(mqttClient);
    }
    checkWifiConnection(); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.