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 ?