span
span

Reputation: 5624

Callback for when a connection is established in Paho

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

Answers (1)

cosmin.danisor
cosmin.danisor

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

Related Questions