Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT serverConnection lost #44

Open
vamshik113 opened this issue Dec 17, 2018 · 8 comments
Open

MQTT serverConnection lost #44

vamshik113 opened this issue Dec 17, 2018 · 8 comments

Comments

@vamshik113
Copy link

vamshik113 commented Dec 17, 2018

MQTT plugin suddenly disconnects and when tried to reconnect back it shows the error:
Error while connecting to MQTT serverConnection lost (32109) - java.net.SocketException: Software caused connection abort.
This happens very often. Is there any fix for this?

@NiragShah
Copy link

Hi There,
I am also getting same issue in app.
When i connect app with sensors and publish data, after 2-3 mins app suddenly drops connection to MQTT broker with following error.
"Error while connecting to MQTT serverConnection lost (32109) - java.net.SocketException: Connection timed out"
Any help would be appreciated.
Thanks

@adrianmihaila
Copy link

I can help you if you need it...

@vamshik113
Copy link
Author

@adrianmihaila Yes, I'm still facing this issue. Please let me know what is the fix.

@adrianmihaila
Copy link

adrianmihaila commented Apr 10, 2019

@vamshik113, I had the same problem, but I found a workaround.

class MqttClient {
  connect(successCallback) {
    let clientId = 'm-' + device.uuid;

    cordova.plugins.CordovaMqTTPlugin.connect({
      url: MQTT_BROKER_URL,
      port: MQTT_BROKER_PORT,
      clientId: clientId,
      keepAlive: 0,
      reconnectPeriod: 1000,
      clean: false,
      success: successCallback,
      error: (e) => {
        console.error('Mqtt connection error: ' + JSON.stringify(e));
      },
      onConnectionLost: () => {
        this.connect(successCallback); // Here is the magic. On connection lost, you will try to reconnect.
      }
    });
  }
....
}

document.addEventListener('deviceready', () => {
    let mqttClient = new MqttClient();
    mqttClient.connect(() => {
          // Subscribe method is another wrapper for cordova.plugins.CordovaMqTTPlugin.subscribe()
          mqttClient.subscribe(TOPIC, QOS_LEVEL);
    });
});

I made a suite of manual tests and all of them have passed.

Adi

@spilz87
Copy link

spilz87 commented Nov 19, 2021

Hi

I got the same issue when two tablets with the same application connect to MQTT Server (Mosquitto on raspberry pi)

I observe that the application lost connection with server (Error while connecting to MQTT serverConnection lost (32109) - java.net.SocketException: Software caused connection abort) when on an other tablet the application connect.

They should have different Client ID
cordova.plugins.CordovaMqTTPlugin.connect({ url:"tcp://" + config.gateway, port:config.port, clientId:"TABLETTE_" + macAdd, connectionTimeout:3000, willTopicConfig:{qos:0, //default is 0 retain:true, //default is true topic: lastWillTopic, payload: lastWillPayload }, username:config.MQTT_log, password:config.MQTT_PW, keepAlive:10, isBinaryPayload: false });

but I suspect an issue about that and the ClientID is the same for all application (whatever you set as clientId)

any idea ?

@arcoirislabs
Copy link
Owner

Hi,
According to MQTT spec, we cannot reuse same Client ID which is used previously. The broker shall deny connection or close previous connection. The library generates a random Client ID if it is unset or left blank.

@spilz87
Copy link

spilz87 commented Nov 27, 2021

Actually if clientId is not set broker receive id null

It seems the library doesn't generate random clientId

@arcoirislabs
Copy link
Owner

A newer version is being worked on here https://github.com/ameykshirsagar/cordova-plugin-mqtt . You can keep a tab on developments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants