Skip to content

Commit d0731e9

Browse files
authored
Extend Space ID support to all nodes #55
Extend Space ID support to all nodes
2 parents 4b402ee + 92f2a51 commit d0731e9

6 files changed

+141
-100
lines changed

arduino-iot-cloud.html

+17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
property: {value: "", validate: validator},
4646
name: {value: "", validate: validator},
4747
propname: {value: ""},
48+
organization: {value: ""},
4849
defaultname: {value: true}
4950
};
5051

@@ -424,6 +425,10 @@
424425
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
425426
<input type="text" id="node-input-connection">
426427
</div>
428+
<div class="form-row">
429+
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
430+
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
431+
</div>
427432
<div class="form-row">
428433
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i> <span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
429434
<select id="node-input-thing">
@@ -455,6 +460,10 @@
455460
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
456461
<input type="text" id="node-input-connection">
457462
</div>
463+
<div class="form-row">
464+
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
465+
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
466+
</div>
458467
<div class="form-row">
459468
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
460469
<select id="node-input-thing">
@@ -492,6 +501,10 @@
492501
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
493502
<input type="text" id="node-input-connection">
494503
</div>
504+
<div class="form-row">
505+
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
506+
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
507+
</div>
495508
<div class="form-row">
496509
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i> <span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
497510
<select id="node-input-thing">
@@ -527,6 +540,10 @@
527540
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
528541
<input type="text" id="node-input-connection">
529542
</div>
543+
<div class="form-row">
544+
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
545+
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
546+
</div>
530547
<div class="form-row">
531548
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
532549
<select id="node-input-thing">

arduino-iot-cloud.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ module.exports = function (RED) {
8484
this.propertyName = config.name;
8585
this.sendasdevice = config.sendasdevice;
8686
this.device = config.device
87-
87+
const opts = {}
88+
if (this.organization) {
89+
opts.xOrganization = this.organization;
90+
}
8891
this.on('input', async function (msg) {
8992
try {
90-
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, this.sendasdevice ? this.device : undefined);
93+
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, opts, this.sendasdevice ? this.device : undefined);
9194
var s;
9295
if (typeof msg.payload !== "object") {
9396
s = getStatus(msg.payload);
@@ -157,6 +160,10 @@ module.exports = function (RED) {
157160
this.thing = config.thing;
158161
this.propertyId = config.property;
159162
this.propertyName = config.name;
163+
const opts = {}
164+
if (this.organization) {
165+
opts.xOrganization = this.organization;
166+
}
160167
node.on('input', async function () {
161168
try{
162169
const now = moment();
@@ -165,7 +172,7 @@ module.exports = function (RED) {
165172
if (count !== null && count !== "" && count !== undefined && Number.isInteger(parseInt(count)) && parseInt(count) !== 0) {
166173
const start = now.subtract(count * this.timeWindowUnit, 'second').format();
167174

168-
const result = await this.arduinoRestClient.getSeries(this.thing, this.propertyId, start, end);
175+
const result = await this.arduinoRestClient.getSeries(this.thing, this.propertyId, start, end, opts);
169176
const times = result.responses[0].times;
170177
const values = result.responses[0].values;
171178
let data = [];
@@ -241,19 +248,19 @@ module.exports = function (RED) {
241248
this.status({});
242249
this.timeWindowCount = config.timeWindowCount;
243250
this.timeWindowUnit = config.timeWindowUnit;
251+
this.organization = config.organization;
244252
if (connectionConfig && config.thing !== "" && config.thing !== "0" && config.property !== "" && config.property !== "0") {
245253
try {
246254
this.arduinoRestClient = await connectionManager.getClientHttp(connectionConfig);
247255
if (this.arduinoRestClient){
248256
this.arduinoRestClient.openConnections++;
249257
if (config.thing !== "" && config.property !== "") {
250-
this.organization = config.organization;
251258
this.thing = config.thing;
252259
this.propertyId = config.property;
253260
this.propertyName = config.name;
254261
const pollTime = this.timeWindowCount * this.timeWindowUnit;
255262
if (pollTime !== null && pollTime !== "" && pollTime !== undefined && Number.isInteger(parseInt(pollTime)) && parseInt(pollTime) !== 0) {
256-
this.poll(connectionConfig, pollTime);
263+
this.poll(connectionConfig, pollTime, this.organization);
257264
this.on('close', function (done) {
258265
connectionManager.deleteClientHttp(connectionConfig.credentials.clientid).then(() => { done(); });
259266
if (this.pollTimeoutPoll)
@@ -283,9 +290,13 @@ module.exports = function (RED) {
283290
realConstructor.apply(this, [config]);
284291
}
285292
ArduinoIotInputPoll.prototype = {
286-
poll: async function (connectionConfig, pollTime) {
293+
poll: async function (connectionConfig, pollTime, organization) {
287294
try {
288-
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId);
295+
const opts = {}
296+
if (organization) {
297+
opts.xOrganization = organization;
298+
}
299+
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId, opts);
289300
this.send(
290301
{
291302
topic: property.name,
@@ -298,7 +309,7 @@ module.exports = function (RED) {
298309
this.status({ fill: "grey", shape: "dot", text: s });
299310
else
300311
this.status({});
301-
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime) }, pollTime * 1000);
312+
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime, organization) }, pollTime * 1000);
302313
} catch (err) {
303314
if(err.response && err.response.res && err.response.request){
304315
console.log('statusCode: '+ err.response.res.statusCode +'\n'+
@@ -336,9 +347,13 @@ module.exports = function (RED) {
336347
this.thing = config.thing;
337348
this.propertyId = config.property;
338349
this.propertyName = config.name;
350+
const opts = {}
351+
if (this.organization) {
352+
opts.xOrganization = this.organization;
353+
}
339354
node.on('input', async function () {
340355
try{
341-
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId);
356+
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId, opts);
342357
this.send(
343358
{
344359
topic: property.name,

package-lock.json

+91-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)