MQTT Over Websockets in Android

怎甘沉沦 提交于 2019-12-13 02:59:49

问题


I am using Paho Android Service for MQTT over web sockets.

https://www.hivemq.com/blog/mqtt-client-library-enyclopedia-paho-android-service

My question is how do I set the Broker WSS URI which has a query parameter in it.

For example: wss://test.amazon.com:80/mqtt?query1=value&query2=value

Edit

If we add the complete URL, the PAHO client library throws following exception:

MqttException (0) - java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
W/System.err:     at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
W/System.err:     at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)

Edit 2

CLIENT = new MqttAndroidClient(this, "wss://test.amazon.com:80/mqtt?query1=value&query2=value", clientId, new MemoryPersistence());
CLIENT.setCallback(this);

MQTT_CONNECTION_OPTIONS = new MqttConnectOptions();
MQTT_CONNECTION_OPTIONS.setCleanSession(true);

try {
    IMqttToken token = CLIENT.connect(MQTT_CONNECTION_OPTIONS);
    token.setActionCallback(new IMqttActionListener() {
        @Override
        public void onSuccess(IMqttToken asyncActionToken) {
            Log.v("tag", "onsuccess");
        }

        @Override
        public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
            exception.printStackTrace();
        }
    });


} catch (MqttException e) {
    e.printStackTrace();
}

回答1:


Changing version from

compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'

to

compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'

resolved this issue. They have fixed this issue in v1.2.0



来源:https://stackoverflow.com/questions/47563116/mqtt-over-websockets-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!