Skip to content

Commit 83e22a0

Browse files
committed
support client-mqtt lib interoperability
1 parent a0855d8 commit 83e22a0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

arduino-cloud.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function (RED) {
1717
this.propertyVariableName = config.variableName;
1818
this.arduinoClient = await connectionManager.getClientMqtt(connectionConfig, RED);
1919
if (this.arduinoClient && this.arduinoClient.connection.connected) {
20-
await this.arduinoClient.onPropertyValue(this.thing, this.propertyVariableName, config.id,(msg) => {
20+
await this.arduinoClient.onPropertyValue(this.thing, this.propertyVariableName,(msg) => {
2121
this.send(
2222
{
2323
topic: this.propertyName,
@@ -30,7 +30,7 @@ module.exports = function (RED) {
3030
this.status({ fill: "grey", shape: "dot", text: s });
3131
else
3232
this.status({});
33-
});
33+
},config.id);
3434
}else{
3535
this.status({ fill: "red", shape: "ring", text: "Connection Error" });
3636
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,19 @@ class ArduinoClientMqtt {
564564
return arrayBufferToBase64(cborEncoded);
565565
};
566566

567-
onPropertyValue(thingId, name,nodeId, cb) {
567+
onPropertyValue(thingId, name, cb,nodeId) {
568568
if (!name) {
569569
throw new Error('Invalid property name');
570570
}
571571
if (typeof cb !== 'function') {
572572
throw new Error('Invalid callback');
573573
}
574+
var node;
575+
if(!nodeId){
576+
node=1
577+
}else{
578+
node=nodeId;
579+
}
574580
const propOutputTopic = `/a/t/${thingId}/e/o`;
575581

576582
this.subscribedTopics[thingId] = {
@@ -582,7 +588,7 @@ class ArduinoClientMqtt {
582588
this.propertyCallback[propOutputTopic] = {};
583589
this.propertyCallback[propOutputTopic][name] = [];
584590
this.propertyCallback[propOutputTopic][name].push({
585-
nodeId: nodeId,
591+
nodeId: node,
586592
callback:cb
587593
});
588594

@@ -592,12 +598,12 @@ class ArduinoClientMqtt {
592598
if (this.propertyCallback[propOutputTopic] && !this.propertyCallback[propOutputTopic][name]) {
593599
this.propertyCallback[propOutputTopic][name] = [];
594600
this.propertyCallback[propOutputTopic][name].push({
595-
nodeId: nodeId,
601+
nodeId: node,
596602
callback:cb
597603
});
598604
}else if(this.propertyCallback[propOutputTopic] && this.propertyCallback[propOutputTopic][name]){
599605
this.propertyCallback[propOutputTopic][name].push({
600-
nodeId: nodeId,
606+
nodeId: node,
601607
callback:cb
602608
});
603609
}
@@ -609,11 +615,17 @@ class ArduinoClientMqtt {
609615
if (!name) {
610616
throw new Error('Invalid property name');
611617
}
618+
var node;
619+
if(!nodeId){
620+
node=1
621+
}else{
622+
node=nodeId;
623+
}
612624
const propOutputTopic = `/a/t/${thingId}/e/o`;
613625
var pos=-1;
614626
for(var i=0; i<this.propertyCallback[propOutputTopic][name].length; i++){
615627
var cbObject=this.propertyCallback[propOutputTopic][name][i];
616-
if(cbObject.nodeId===nodeId){
628+
if(cbObject.nodeId===node){
617629
pos=i;
618630
break;
619631
}

0 commit comments

Comments
 (0)