Coder Social home page Coder Social logo

Comments (8)

NiragShah avatar NiragShah commented on August 22, 2024

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

from cordova-plugin-mqtt.

adrianmihaila avatar adrianmihaila commented on August 22, 2024

I can help you if you need it...

from cordova-plugin-mqtt.

vamshik113 avatar vamshik113 commented on August 22, 2024

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

from cordova-plugin-mqtt.

adrianmihaila avatar adrianmihaila commented on August 22, 2024

@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

from cordova-plugin-mqtt.

spilz87 avatar spilz87 commented on August 22, 2024

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 ?

from cordova-plugin-mqtt.

arcoirislabs avatar arcoirislabs commented on August 22, 2024

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.

from cordova-plugin-mqtt.

spilz87 avatar spilz87 commented on August 22, 2024

Actually if clientId is not set broker receive id null

It seems the library doesn't generate random clientId

from cordova-plugin-mqtt.

arcoirislabs avatar arcoirislabs commented on August 22, 2024

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

from cordova-plugin-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.