Skip to content

Commit 755011c

Browse files
committed
Add send as device option to output node
1 parent 76fa40b commit 755011c

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

arduino-iot-cloud.html

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
ret['variableName'] = {value: ""};
5353
}
5454

55+
if (nodeName === "property out") {
56+
ret['sendasdevice'] = {value: false};
57+
}
58+
5559
return ret;
5660
}
5761

@@ -100,6 +104,10 @@
100104
}
101105
}
102106
});
107+
$("#node-input-sendasdevice").change(() => {
108+
sendasdevice = $("#node-input-sendasdevice").val();
109+
this.sendasdevice = sendasdevice;
110+
});
103111
$("#node-input-organization").change(() => {
104112
const connection = $("#node-input-connection").val();
105113
const organization = $("#node-input-organization").val();
@@ -382,6 +390,10 @@
382390
<label for="node-input-name"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.name"></span></label>
383391
<input type="text" id="node-input-name" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.name">
384392
</div>
393+
<div class="form-row">
394+
<label for="node-input-name"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.send-mode"></span></label>
395+
<input type="checkbox" id="node-input-sendasdevice">
396+
</div>
385397

386398
</script>
387399

arduino-iot-cloud.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,25 @@ module.exports = function (RED) {
8282
this.thing = config.thing;
8383
this.propertyId = config.property;
8484
this.propertyName = config.name;
85+
this.sendasdevice = config.sendasdevice;
8586

86-
//console.log("Node Constructor: ", config.name);
87-
try {
88-
const opts = {}
89-
if (this.organization) {
90-
opts.xOrganization = this.organization;
87+
if (this.sendasdevice) {
88+
try {
89+
const opts = {}
90+
if (this.organization) {
91+
opts.xOrganization = this.organization;
92+
}
93+
ret = await this.arduinoRestClient.getThing(this.thing, opts);
94+
this.device_id = ret.device_id;
95+
} catch (error) {
96+
// Handle API call error
97+
console.error('Error making API call:', error.message);
9198
}
92-
ret = await this.arduinoRestClient.getThing(this.thing, opts);
93-
this.device_id = ret.device_id;
94-
//console.log(" Thing info: ", JSON.stringify(ret));
95-
//console.log(" Device ID: ", this.device_id);
96-
} catch (error) {
97-
// Handle API call error
98-
console.error('Error making API call:', error.message);
9999
}
100-
101100

102101
this.on('input', async function (msg) {
103102
try {
104-
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, this.device_id);
103+
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, this.sendasdevice ? this.device_id : undefined);
105104
var s;
106105
if (typeof msg.payload !== "object") {
107106
s = getStatus(msg.payload);

locales/en-US/arduino-iot-cloud.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"organization": "Space ID",
1010
"hist-label":"Time filter",
1111
"poll-label":"Poll Every",
12+
"send-mode":"Send as device",
1213
"placeholders":{
1314
"name":"Name",
1415
"no-thing-selected":"No thing selected",

0 commit comments

Comments
 (0)