0

こんにちは、登録したばかりの Android デバイスで mqtt に接続しようとしていますが、エラーが発生し続けます

Not authorized to connect (5)

これは私のコードの一部です

        client = new MqttAndroidClient(context, connectionURI, clientID);
        client.setCallback(callbacks);

        String username = IOT_DEVICE_USERNAME;
        char[] password = this.getAuthorizationToken().toCharArray();

        MqttConnectOptions options = new MqttConnectOptions();
        options.setCleanSession(true);
        options.setUserName(username);
        options.setPassword(password);

        Log.d(TAG, "Connecting to server: " + connectionURI);
        try {
            // connect
            return client.connect(options, context, listener);
        } catch (MqttException e) {
            Log.e(TAG, "Exception caught while attempting to connect to server", e.getCause());
            throw e;
        }

ここで、IOT_DEVICE_USERNAMEはストリング「use-token-auth」 であり、connectionUri「tcp://<"organization">.messaging.internetofthings.ibmcloud.com:8883」です。

他に興味深いのは、このエラーの直前にこのログを取得することです

Unregister alarmreceiver to MqttServiced:<"organisation">:<"DeviceType">:<"deviceId">

これがエラーのstackTraceです

07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err: Not authorized to connect (5)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:28)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:988)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:140)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-06 12:27:24.214 9009-9009/wibicom.wibeacon3 W/System.err:     at java.lang.Thread.run(Thread.java:818)
4

2 に答える 2

0

このエラーが見つかりました:

トークン認証に失敗しました (デバイス/ゲートウェイがデータベースに見つかりません): ClientID='d:4rxa4d:AndroidDevice:1c39476b8dd0'

AndroidDevice のデバイス・タイプを作成し、ID 1c39476b8dd0 を Watson IoT Platform の組織に登録しましたか?

このチュートリアルでは、デバイスを登録する方法を示します。

于 2017-07-06T14:07:59.953 に答える