Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b15da85
first draft mqtt integration
fabik111 Nov 27, 2019
25a93d4
add disconnect method
fabik111 Nov 28, 2019
f96bed1
add arduino-iot-client-mqtt lib
fabik111 Nov 28, 2019
420e76f
first draft mqtt integration
fabik111 Nov 27, 2019
675b161
add disconnect method
fabik111 Nov 28, 2019
eca069f
add arduino-iot-client-mqtt lib
fabik111 Nov 28, 2019
e0ba2f6
Merge branch 'mqtt-lib' of https://github.com/bcmi-labs/node-red-cont…
ilcato Nov 28, 2019
da12015
refactor libs
fabik111 Nov 29, 2019
9332982
fix refactor
fabik111 Nov 29, 2019
8353a95
Merge branch 'mqtt-lib' of https://github.com/bcmi-labs/node-red-cont…
ilcato Nov 29, 2019
9cfb7d4
fix
ilcato Nov 29, 2019
06622f4
fix class method
fabik111 Nov 29, 2019
cf4eea1
fixed paho client
ilcato Nov 29, 2019
acf1c15
Many fixes
ilcato Nov 30, 2019
d2dbb6c
Updated icons and alignment
ilcato Dec 1, 2019
d9e89a6
Fix object reference error
ilcato Dec 1, 2019
f1d6cf3
Added mqtt env params
ilcato Dec 1, 2019
e796ba4
Refactor
ilcato Dec 1, 2019
e1ebbcd
Refactored with mqtt library instead of paho-client
ilcato Dec 1, 2019
78a81a5
add mutex and fix bug
fabik111 Dec 2, 2019
c5b6657
first draft mqtt integration
fabik111 Nov 27, 2019
bb90b13
add disconnect method
fabik111 Nov 28, 2019
77ca73f
add arduino-iot-client-mqtt lib
fabik111 Nov 28, 2019
af4de0d
first draft mqtt integration
fabik111 Nov 27, 2019
c1396eb
add disconnect method
fabik111 Nov 28, 2019
ae8c42c
add arduino-iot-client-mqtt lib
fabik111 Nov 28, 2019
b37c023
refactor libs
fabik111 Nov 29, 2019
bb8f8f7
fix refactor
fabik111 Nov 29, 2019
287db6e
fix
ilcato Nov 29, 2019
6555cdf
fix class method
fabik111 Nov 29, 2019
f7dc6a7
fixed paho client
ilcato Nov 29, 2019
8610ec3
Many fixes
ilcato Nov 30, 2019
935d8c1
Updated icons and alignment
ilcato Dec 1, 2019
01d7044
Fix object reference error
ilcato Dec 1, 2019
281afcd
Added mqtt env params
ilcato Dec 1, 2019
5828177
Refactor
ilcato Dec 1, 2019
2448e42
Refactored with mqtt library instead of paho-client
ilcato Dec 1, 2019
3cbd012
add mutex and fix bug
fabik111 Dec 2, 2019
c4c0a32
Merge branch 'mqtt-lib' of https://github.com/bcmi-labs/node-red-cont…
fabik111 Dec 2, 2019
0b6b464
fix disconnect procedures
fabik111 Dec 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add mutex and fix bug
  • Loading branch information
fabik111 authored and ilcato committed Dec 2, 2019
commit 3cbd012f1a3ab02d4ef8478a8000d3cda744b2ef
2 changes: 2 additions & 0 deletions arduino-cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = function (RED) {
else
this.status({});
});
}else{
this.status({ fill: "red", shape: "ring", text: "Connection Error" });
}
this.on('close', function (done) {
connectionManager.deleteClientMqtt(connectionConfig.credentials.clientid, this.thing, this.propertyName).then(() => { done(); });
Expand Down
5 changes: 2 additions & 3 deletions arduino-iot-client-mqtt/arduino-iot-client-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ArduinoClientMqtt {
new ArduinoCloudError(errorCode, errorMessage),
);
});

client.on("message", (topic, msg) => {
if (topic.indexOf('/s/o') > -1) {
client.topics[topic].forEach((cb) => {
Expand Down Expand Up @@ -562,7 +562,7 @@ class ArduinoClientMqtt {
topic: propOutputTopic,
cb,
};

this.numSubscriptions++;
if (!this.propertyCallback[propOutputTopic]) {
this.propertyCallback[propOutputTopic] = {};
this.propertyCallback[propOutputTopic][name] = cb;
Expand All @@ -571,7 +571,6 @@ class ArduinoClientMqtt {

if (this.propertyCallback[propOutputTopic] && !this.propertyCallback[propOutputTopic][name]) {
this.propertyCallback[propOutputTopic][name] = cb;
this.numSubscriptions++;
}
return Promise.resolve(propOutputTopic);
};
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@arduino/arduino-iot-client": "^1.0.1",
"@arduino/cbor-js": "github:arduino/cbor-js",
"async-mutex": "^0.1.4",
"async-request": "^1.2.0",
"jws": "^3.2.2",
"lodash": "^4.17.15",
Expand Down
16 changes: 15 additions & 1 deletion utils/arduino-connection-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ArduinoClientMqtt = require ('../arduino-iot-client-mqtt/arduino-iot-clien
const accessTokenUri = process.env.NODE_RED_ACCESS_TOKEN_URI || 'https://login.arduino.cc/oauth/token';
const accessTokenAudience = process.env.NODE_RED_ACCESS_TOKEN_AUDIENCE || 'https://api2.arduino.cc/iot';
const arduinoCloudHost = process.env.NODE_RED_MQTT_HOST || 'wss.iot.arduino.cc';

const Mutex = require('async-mutex').Mutex;
/**
* {
* clientId: clientId,
Expand All @@ -17,6 +17,9 @@ const arduinoCloudHost = process.env.NODE_RED_MQTT_HOST || 'wss.iot.arduino.cc';
* }
*/
var connections=[];
const getClientMutex = new Mutex();



async function getToken(connectionConfig){
var options = {
Expand Down Expand Up @@ -48,9 +51,11 @@ async function getToken(connectionConfig){
}

async function getClientMqtt(connectionConfig){

if (!connectionConfig || !connectionConfig.credentials) {
throw new Error("Cannot find cooonection config or credentials.");
}
const releaseMutex = await getClientMutex.acquire();
try{
let user = findUser(connectionConfig.credentials.clientid);
let clientMqtt;
Expand Down Expand Up @@ -102,17 +107,22 @@ async function getClientMqtt(connectionConfig){
connections[user].clientMqtt=clientMqtt;
}
}
releaseMutex();

return clientMqtt;
}catch(err){
console.log(err);
releaseMutex();
}

}

async function getClientHttp(connectionConfig){

if (!connectionConfig || !connectionConfig.credentials) {
throw new Error("Cannot find cooonection config or credentials.");
}
const releaseMutex = await getClientMutex.acquire();
try{
var user = findUser(connectionConfig.credentials.clientid);
var clientHttp;
Expand Down Expand Up @@ -143,10 +153,14 @@ async function getClientHttp(connectionConfig){
connections[user].clientHttp=clientHttp;
}
}
releaseMutex();
return clientHttp;
}catch(err){
console.log(err);
releaseMutex();

}

}

function findUser(clientId) {
Expand Down