Search code examples
androidibm-cloudmqttiotpaho

Bluemix quickstart disconnects at publish with Paho MQTT client


I used Paho MQTT client in Android to connect to IBM Bluemix quickstart IoT service. The connection part works well, but when I publish, the cloud application displays that I'm disconnected, but in the client I don't get exceptions.

I use this permission:

<uses-permission android:name="android.permission.INTERNET"/>

Connect:

String broker       = "tcp://quickstart.messaging.internetofthings.ibmcloud.com:1883";
String clientId     = "d:quickstart:iotqs-sensor:myDeviceID";

try {
    client = new MqttClient(broker, clientId, null);
    MqttConnectOptions connOpts = new MqttConnectOptions();
    client.connect(connOpts);
} catch(MqttException me) {

Publish:

String topic        = "iot-2/evt/iotsensor/fmt/jon";
String content      = "{ \"d\" : { \"data\" : 5 } }";

try {
    MqttMessage message = new MqttMessage(content.getBytes());
    message.setQos(0);
    client.publish(topic, message);
} catch(MqttException me) {

The strange thing is: this code worked yesterday. What could be the problem? The next step will be to connect and publish to my own Bluemix IoT service, but if I can't send messages to the demo, I can't hope for more.

UPDATE: If I connect, and publish, the quickstart app shows that I'm disconnected, but the client still lets me publish for about 3 secs, after that I get an exception: 32104 (the client is not connected).


Solution

  • A Device must be registered before it can connect. Refer to quickstart documentation at https://docs.internetofthings.ibmcloud.com/messaging/devices.html#/ I don't see any devices registered under your org. Also, under the org it shows your email/ID as "expired". Please sign in at https://internetofthings.ibmcloud.com/#/ and add yourself as a permanent user under the access tab.