Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Using Paho Android MQTT service.

I am new to Android. Also, I hope, I am using the right forum. Can you please guide me how to use the Android MQTT service for publish and subscribe ?

I have built the Android service JAR successfully with the Paho MQTT client 1.0.0. Also, I have been able to get the Android sample (the one that comes with Android service download) on my Samsung Galaxy phone.

In the onClick() method for a button in my layout, after validations, I am doing the following:

1. Obtain a new MqttAndroidClient instance (c) with context, broker URL and client Id.
2. Do IMqttToken tok = c.connect(); This works as I can see mosquitto broker log this connection.
3. tok.waitForCompletion(3000); This fails with due to a time out.

I commented out the waitForCompletion and went straight for publishing.
1. c.publish(topic, msg). This causes a NullPointerException that points to MqttAndroidClient.publish().

Back to the top