Skip to content

Commit 448fda7

Browse files
committed
2 parents 6b68376 + 83e22a0 commit 448fda7

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
@@ -570,13 +570,19 @@ class ArduinoClientMqtt {
570570
return arrayBufferToBase64(cborEncoded);
571571
};
572572

573-
onPropertyValue(thingId, name,nodeId, cb) {
573+
onPropertyValue(thingId, name, cb,nodeId) {
574574
if (!name) {
575575
throw new Error('Invalid property name');
576576
}
577577
if (typeof cb !== 'function') {
578578
throw new Error('Invalid callback');
579579
}
580+
var node;
581+
if(!nodeId){
582+
node=1
583+
}else{
584+
node=nodeId;
585+
}
580586
const propOutputTopic = `/a/t/${thingId}/e/o`;
581587

582588
this.subscribedTopics[thingId] = {
@@ -588,7 +594,7 @@ class ArduinoClientMqtt {
588594
this.propertyCallback[propOutputTopic] = {};
589595
this.propertyCallback[propOutputTopic][name] = [];
590596
this.propertyCallback[propOutputTopic][name].push({
591-
nodeId: nodeId,
597+
nodeId: node,
592598
callback:cb
593599
});
594600

@@ -598,12 +604,12 @@ class ArduinoClientMqtt {
598604
if (this.propertyCallback[propOutputTopic] && !this.propertyCallback[propOutputTopic][name]) {
599605
this.propertyCallback[propOutputTopic][name] = [];
600606
this.propertyCallback[propOutputTopic][name].push({
601-
nodeId: nodeId,
607+
nodeId: node,
602608
callback:cb
603609
});
604610
}else if(this.propertyCallback[propOutputTopic] && this.propertyCallback[propOutputTopic][name]){
605611
this.propertyCallback[propOutputTopic][name].push({
606-
nodeId: nodeId,
612+
nodeId: node,
607613
callback:cb
608614
});
609615
}
@@ -615,11 +621,17 @@ class ArduinoClientMqtt {
615621
if (!name) {
616622
throw new Error('Invalid property name');
617623
}
624+
var node;
625+
if(!nodeId){
626+
node=1
627+
}else{
628+
node=nodeId;
629+
}
618630
const propOutputTopic = `/a/t/${thingId}/e/o`;
619631
var pos=-1;
620632
for(var i=0; i<this.propertyCallback[propOutputTopic][name].length; i++){
621633
var cbObject=this.propertyCallback[propOutputTopic][name][i];
622-
if(cbObject.nodeId===nodeId){
634+
if(cbObject.nodeId===node){
623635
pos=i;
624636
break;
625637
}

0 commit comments

Comments
 (0)