我正在尝试将mqtt与PAHO Mqtt安卓库连接。但它对我不起作用。我认为我的服务器uri无效,但我不确定。
val clientId = MqttAsyncClient.generateClientId();
val url = "wss://xxxxxxx.iot.us-east-1.amazonaws.com/mqtt?...."
client = MqttAndroidClient(this,url, clientId)
val token = client.connect()
token.actionCallback = object : IMqttActionListener {
override fun onSuccess(asyncActionToken: IMqttToken) {
// We are connected
Log.i(TAG,"onSuccess")
}
override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
exception.printStackTrace()
Log.i(TAG,"onFailure")
}
}
我在logcat中看到MqttException(0)。为了解异常原因,我查看了MqttException类的decleration。我看到了:
public class MqttException extends Exception {
public static final short REASON_CODE_CLIENT_EXCEPTION = 0x00;
}
Shorty,我不知道为什么它没有连接到mqtt。