hirotakaster / MQTT

MQTT for Photon, Spark Core
Other
216 stars 118 forks source link

Lose connection after first publish #6

Closed CptanPanic closed 8 years ago

CptanPanic commented 8 years ago

Hello, I am trying to use your library on a Particle Core, to connect to cloudmqtt server. It seems like it connects initially, but when I issue the first publish() command, the broker never gets any data, and the next time through loop isConnected() returns false. Any ideas? Have you ever tried using cloudmqtt?


    if (client.isConnected())
    {
        sprintf(publishString,"%f.1",sht1x.readHumidity());
        client.publish("/output/humidity",publishString);
        Spark.publish("/output/humidity",publishString);
    }
    else
    {
        Spark.publish("mqtt-down");
    }
hirotakaster commented 8 years ago

Hi, I use cloudmqtt and Photon/MQTT, but don't have any problem. like this. try on new Photon firmware?

    if (client.isConnected()) {
        client.publish("/outTopic","hello world");
        client.loop();
    } else {
        // publish/subscribe
        client.connect("mqttclient", "user_id", "password");
        if (client.isConnected()) {
            client.publish("/outTopic","hello world");
            client.subscribe("/inTopic");
            RGB.color(0, 0, 0);
        }
    }
    delay(1000);