Reputation: 5624
I'm using the Eclipse MQTT library Paho and I can't find a way to decide when the clients connection to the broker has been established. Does anyone know if there is a way to do this currently?
I can't seem to find any information about this in the MqttCallback class in the documentation nor can I find a bug or feature request of it.
Thanks.
Upvotes: 0
Views: 2537
Reputation: 963
The client has a method that returns the status of the connection, if that is what you are looking for
public class MQTT_Client implements MqttCallback {
private MqttClient mqtt;
public boolean connect(){
try{
mqtt = new MqttClient(....);
....
mqtt.connect();
//Connected
return true;
catch(MqttException e){
//Connection failed
return false;
}
}
@Override
public void connectionLost(Throwable cause) {
//Connection Lost
}
This method can be used to check connection status:
boolean connected = mqtt.isConnected();
Upvotes: 1