4

I am trying to publish a message to IBM BlueMix IoTF Service using the Eclipse Paho MQTT Android Client. When I call the MqttAndroidClient#connect() method, I get an error in the onFailure() callback - Not authorized to connect (5)

My connection code is (This code is run from an OnClick event from a button) -

    mqtt = new MqttAndroidClient(
            MainActivity.this,
            "tcp://<org-id>.messaging.internetofthings.ibmcloud.com:1883",
            "d:<org-id>:MQTTdevices:watson-android"
    );

    MqttConnectOptions options = new MqttConnectOptions();

    options.setCleanSession(true);

    options.setUserName("use-token-auth");
    options.setPassword("<token>".toCharArray());

    Log.i(TAG, "attempting connection");

    try {
        mqtt.connect(options, new IMqttActionListener() {
            @Override
            public void onSuccess(IMqttToken asyncActionToken) {
                Log.i(TAG, "connected to mqtt");
                isconneted = true;
            }

            @Override
            public void onFailure(IMqttToken asyncActionToken, Throwable e) {
                Log.e(TAG, "mqtt connect failed", e);
                isconneted = false;
            }
        });
    } catch (MqttException e) {
        Log.e(TAG, "mqtt connect failed", e);
    }

Using the same credentials, I can connect to IoTF and publish messages using mosquitto_pub command line client. How do I get rid of this error ?

Rohan
  • 1,180
  • 2
  • 15
  • 28
  • If you will send me you org ID I will check the IOT logs to see if I can get further information about your connection error. – ValerieLampkin Feb 02 '16 at 13:35
  • @ValerieLampkin my org id is "2w14lf". – Rohan Feb 03 '16 at 04:36
  • I see some errors in the log Closing TCP connection: ConnectionID=10723618 ClientID="d:2w14lf:MQTTdevices:watson-android" Protocol=mqtt4-tcp Endpoint="mqtt" From=14.195.95.136:30760 UserID="" Uptime=0 RC=180 Reason="The operation is not authorized." ReadBytes=49 ReadMsg=0 WriteBytes=0 WriteMsg=0 LostMsg=0. Invalid userID () for device auth: ClientID='d:2w14lf:MQTTdevices:watson-android' I am investigating further. – ValerieLampkin Feb 03 '16 at 13:15
  • @ValerieLampkin any updates ? – Rohan Feb 05 '16 at 12:43
  • It seems like the correct credentials are not being passed by your application I am checking with a colleague for further insight. – ValerieLampkin Feb 05 '16 at 16:26
  • sorry for the delay replying. Are you still having this issue? – ValerieLampkin Mar 01 '16 at 19:32

0 Answers0