Skip to content

Commit bf8c0ca

Browse files
committed
fix reconnect
1 parent b82a16c commit bf8c0ca

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

utils/arduino-connection-manager.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ async function getClientMqtt(connectionConfig, RED) {
8888
},
8989
useCloudProtocolV2: true
9090
};
91-
await clientMqtt.connect(ArduinoCloudOptions);
92-
const timeout = setTimeout(() => { updateToken(connectionConfig) }, tokenInfo.expires_in * 1000);
9391
connections.push({
9492
clientId: connectionConfig.credentials.clientid,
9593
connectionConfig: connectionConfig,
@@ -99,6 +97,10 @@ async function getClientMqtt(connectionConfig, RED) {
9997
clientHttp: null,
10098
timeoutUpdateToken: timeout
10199
});
100+
await clientMqtt.connect(ArduinoCloudOptions);
101+
102+
const timeout = setTimeout(() => { updateToken(connectionConfig) }, tokenInfo.expires_in * 1000);
103+
102104
} else {
103105
// TODO: what happens when token is undefined?
104106
clientMqtt = undefined;
@@ -133,8 +135,9 @@ async function getClientMqtt(connectionConfig, RED) {
133135
},
134136
useCloudProtocolV2: true
135137
};
136-
await clientMqtt.connect(ArduinoCloudOptions);
137138
connections[user].clientMqtt = clientMqtt;
139+
await clientMqtt.connect(ArduinoCloudOptions);
140+
138141
}
139142
}
140143
releaseMutex();
@@ -269,7 +272,9 @@ async function deleteClientHttp(clientId) {
269272
async function reconnectMqtt(clientId) {
270273
var user = findUser(clientId);
271274
if (user !== -1) {
272-
await connections[user].clientMqtt.reconnect();
275+
if(connections[user].clientMqtt){
276+
await connections[user].clientMqtt.reconnect();
277+
}
273278
}
274279
}
275280

0 commit comments

Comments
 (0)