Open vamshik113 opened 5 years ago
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
I can help you if you need it...
@adrianmihaila Yes, I'm still facing this issue. Please let me know what is the fix.
@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
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 ?
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.
Actually if clientId is not set broker receive id null
It seems the library doesn't generate random clientId
A newer version is being worked on here https://github.com/ameykshirsagar/cordova-plugin-mqtt . You can keep a tab on developments
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?