Skip to content

Commit b72c5b7

Browse files
committed
fix reconnectMqtt
1 parent f097f21 commit b72c5b7

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

arduino-cloud.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ module.exports = function (RED) {
209209
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime) }, pollTime * 1000);
210210
} catch (err) {
211211
console.log(err);
212+
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime) }, pollTime * 1000);
212213
this.status({ fill: "red", shape: "dot", text: "Error getting value" });
213214
}
214215
}

arduino-iot-client-mqtt/arduino-iot-client-mqtt.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ class ArduinoClientMqtt {
214214
return resolve();
215215
});
216216
}
217+
218+
async reconnect() {
219+
await this.connection.reconnect();
220+
};
221+
217222
async updateToken(token) {
218223
// This infinite loop will exit once the reconnection is successful -
219224
// and will pause between each reconnection tentative, every 5 secs.

utils/arduino-connection-manager.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ async function getClientMqtt(connectionConfig) {
6868
host: arduinoCloudHost,
6969
token: tokenInfo.token,
7070
onDisconnect: () => {
71-
reconnectMqtt(connectionConfig.credentials.clientid);
7271
console.log(`connection lost for ${connectionConfig.credentials.clientid}`);
72+
reconnectMqtt(connectionConfig.credentials.clientid);
73+
7374
},
7475
useCloudProtocolV2: true
7576
};
@@ -97,8 +98,9 @@ async function getClientMqtt(connectionConfig) {
9798
host: "wss.iot.oniudra.cc",
9899
token: connections[user].token,
99100
onDisconnect: () => {
100-
reconnectMqtt(connectionConfig.credentials.clientid);
101101
console.log(`connection lost for ${connectionConfig.credentials.clientid}`);
102+
reconnectMqtt(connectionConfig.credentials.clientid);
103+
102104
},
103105
useCloudProtocolV2: true
104106
};
@@ -238,17 +240,7 @@ async function deleteClientHttp(clientId) {
238240
async function reconnectMqtt(clientId) {
239241
var user = findUser(clientId);
240242
if (user !== -1) {
241-
await connections[user].clientMqtt.disconnect();
242-
const ArduinoCloudOptions = {
243-
host: "wss.iot.oniudra.cc",
244-
token: connections[user].token,
245-
onDisconnect: () => {
246-
reconnectMqtt(connectionConfig.credentials.clientid);
247-
console.log(`connection lost for ${connectionConfig.credentials.clientid}`);
248-
},
249-
useCloudProtocolV2: true
250-
};
251-
await connections[user].clientMqtt.connect(ArduinoCloudOptions);
243+
await connections[user].clientMqtt.reconnect();
252244
}
253245
}
254246

0 commit comments

Comments
 (0)