Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15346

MQTT subscription failed

$
0
0

I used MQTT Explorer to connect and subscribe to the broker and succeeded, but when I switched to code, it returned false or 0.

Following is the main code (for 256dpi/MQTT@^2.5.2):

void test()
{
    WiFiClient wifiClient;
    MQTTClient mqttClient;
    mqttClient.begin(BEMFA_HOST, BEMFA_PORT, wifiClient);
    while (!mqttClient.connect(BEMFA_CLIENT_ID))
    {
        Serial.print(".");
        delay(1000);
    }

    Serial.println("\nconnected!");

    auto r = mqttClient.subscribe("C04E30BA4408002");
    Serial.printf("Subscription result: %d", r);

    while (1)
        ;
}

It printed connected, but mqttClient.subscribe returned false. I tested both 256dpi/MQTT@^2.5.2 and arduino-libraries/ArduinoMqttClient@^0.1.8 and get the same result.
I really want to know why false or 0. I need a clue on what's going on.
Please help!

2 posts - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15346

Trending Articles