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
fix class method
  • Loading branch information
fabik111 authored and ilcato committed Dec 2, 2019
commit 6555cdfdd8085dab39c5fa53e1fc114b14b9f9bb
80 changes: 0 additions & 80 deletions arduino-cloud-mqtt.js

This file was deleted.

41 changes: 21 additions & 20 deletions arduino-iot-client-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class clientMqtt{

// Connect establishes a connection with mqtt, using token as the password, and returns a promise
// of a Symbol identifying the mqtt client
connect = options => new Promise((resolve, reject) => {
connect(options){ return new Promise((resolve, reject) => {
let ssl = false;
if (options.ssl !== false) {
ssl = true;
Expand Down Expand Up @@ -223,8 +223,8 @@ class clientMqtt{

client.connect(connectionOpts);
});

disconnect = () => new Promise((resolve, reject) => {
}
disconnect() {return new Promise((resolve, reject) => {
if (!this.connection) {
return reject(new Error('disconnection failed: connection closed'));
}
Expand Down Expand Up @@ -252,8 +252,8 @@ class clientMqtt{

return resolve();
});

updateToken = async function updateToken(token) {
}
async updateToken(token) {
// This infinite loop will exit once the reconnection is successful -
// and will pause between each reconnection tentative, every 5 secs.
// eslint-disable-next-line no-constant-condition
Expand Down Expand Up @@ -296,7 +296,7 @@ class clientMqtt{
}
};

subscribe = (topic, cb) => new Promise((resolve, reject) => {
subscribe(topic, cb){ return new Promise((resolve, reject) => {
if (!this.connection) {
return reject(new Error('subscription failed: connection closed'));
}
Expand All @@ -312,8 +312,8 @@ class clientMqtt{
onFailure: error => reject(new Error(`subscription failed: ${error.errorMessage}`)),
});
});

unsubscribe = topic => new Promise((resolve, reject) => {
}
unsubscribe(topic) { return new Promise((resolve, reject) => {
if (!this.connection) {
return reject(new Error('disconnection failed: connection closed'));
}
Expand All @@ -323,8 +323,8 @@ class clientMqtt{
onFailure: () => reject(),
});
});

arrayBufferToBase64 = (buffer) => {
}
arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
Expand All @@ -334,32 +334,33 @@ class clientMqtt{
return window.btoa(binary);
};

sendMessage = (topic, message) => new Promise((resolve, reject) => {
sendMessage(topic, message){ return new Promise((resolve, reject) => {
if (!this.connection) {
return reject(new Error('disconnection failed: connection closed'));
}

this.connection.publish(topic, message, 1, false);
return resolve();
});
}

openCloudMonitor = (deviceId, cb) => {
openCloudMonitor(deviceId, cb){
const cloudMonitorOutputTopic = `/a/d/${deviceId}/s/o`;
return subscribe(cloudMonitorOutputTopic, cb);
};


writeCloudMonitor = (deviceId, message) => {
writeCloudMonitor(deviceId, message){
const cloudMonitorInputTopic = `/a/d/${deviceId}/s/i`;
return sendMessage(cloudMonitorInputTopic, message);
};

closeCloudMonitor = (deviceId) => {
closeCloudMonitor(deviceId){
const cloudMonitorOutputTopic = `/a/d/${deviceId}/s/o`;
return unsubscribe(cloudMonitorOutputTopic);
};

toCloudProtocolV2 = (cborValue) => {
toCloudProtocolV2(cborValue){
const cloudV2CBORValue = {};
let cborLabel = null;

Expand Down Expand Up @@ -420,7 +421,7 @@ class clientMqtt{
return cloudV2CBORValue;
};

sendProperty = (thingId, name, value, timestamp) => {
sendProperty(thingId, name, value, timestamp) {
const propertyInputTopic = `/a/t/${thingId}/e/i`;

if (timestamp && !Number.isInteger(timestamp)) {
Expand Down Expand Up @@ -495,7 +496,7 @@ class clientMqtt{
return sendMessage(propertyInputTopic, CBOR.encode([cborValue], true));
};

getSenml = (deviceId, name, value, timestamp) => {
getSenml(deviceId, name, value, timestamp) {
if (timestamp && !Number.isInteger(timestamp)) {
throw new Error('Timestamp must be Integer');
}
Expand Down Expand Up @@ -577,12 +578,12 @@ class clientMqtt{
return senMl;
};

getCborValue = (senMl) => {
getCborValue(senMl) {
const cborEncoded = CBOR.encode(senMl);
return arrayBufferToBase64(cborEncoded);
};

onPropertyValue = (thingId, name, cb) => {
onPropertyValue(thingId, name, cb){
if (!name) {
throw new Error('Invalid property name');
}
Expand Down Expand Up @@ -610,7 +611,7 @@ class clientMqtt{
};


removePropertyValueCallback = (thingId, name) => {
removePropertyValueCallback(thingId, name) {
if (!name) {
throw new Error('Invalid property name');
}
Expand Down