I can not subscribe to MQTT topic from my android application. When i call SubscribeToTopic
function, I get the following Error
"subscription to UserName/feeds/Topic failed: not available"
Here is the code to subscribe
private void SubscribeToTopic(String TopicName, int Qos) {
try {
if (client.isConnected()) {
client.subscribe(TopicName, Qos, null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d("Subscribtion", "Succeed");
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.d("Subscribtion", "Failed", exception);
}
});
}
}
catch (MqttException exception)
{
Log.d("Subscribtion","Failed",exception);
}
}
NOTE: I'm using Eclipse Paho as my MQTT Client and Adafruit IO as Broker. TopicName is something like UserName/feeds/Topic
and Qos is 0
After spending hours finally found solution. There was no problem with code, I only changed the topic to public mode in Adafruit IO dashboard and it worked. The only thing i can not understand is why it is possible to subscribe to private topic from Arduino library but it fails in android.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.