Skip to content

Extend Space ID support to all nodes #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions arduino-iot-cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
property: {value: "", validate: validator},
name: {value: "", validate: validator},
propname: {value: ""},
organization: {value: ""},
defaultname: {value: true}
};

Expand Down Expand Up @@ -424,6 +425,10 @@
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
<input type="text" id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
</div>
<div class="form-row">
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i> <span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
<select id="node-input-thing">
Expand Down Expand Up @@ -455,6 +460,10 @@
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
<input type="text" id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
</div>
<div class="form-row">
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
<select id="node-input-thing">
Expand Down Expand Up @@ -492,6 +501,10 @@
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
<input type="text" id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
</div>
<div class="form-row">
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i> <span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
<select id="node-input-thing">
Expand Down Expand Up @@ -527,6 +540,10 @@
<label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label>
<input type="text" id="node-input-connection">
</div>
<div class="form-row">
<label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label>
<input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization">
</div>
<div class="form-row">
<label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.thing"></span></label>
<select id="node-input-thing">
Expand Down
33 changes: 24 additions & 9 deletions arduino-iot-cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ module.exports = function (RED) {
this.propertyName = config.name;
this.sendasdevice = config.sendasdevice;
this.device = config.device

const opts = {}
if (this.organization) {
opts.xOrganization = this.organization;
}
this.on('input', async function (msg) {
try {
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, this.sendasdevice ? this.device : undefined);
await this.arduinoRestClient.setProperty(this.thing, this.propertyId, msg.payload, opts, this.sendasdevice ? this.device : undefined);
var s;
if (typeof msg.payload !== "object") {
s = getStatus(msg.payload);
Expand Down Expand Up @@ -157,6 +160,10 @@ module.exports = function (RED) {
this.thing = config.thing;
this.propertyId = config.property;
this.propertyName = config.name;
const opts = {}
if (this.organization) {
opts.xOrganization = this.organization;
}
node.on('input', async function () {
try{
const now = moment();
Expand All @@ -165,7 +172,7 @@ module.exports = function (RED) {
if (count !== null && count !== "" && count !== undefined && Number.isInteger(parseInt(count)) && parseInt(count) !== 0) {
const start = now.subtract(count * this.timeWindowUnit, 'second').format();

const result = await this.arduinoRestClient.getSeries(this.thing, this.propertyId, start, end);
const result = await this.arduinoRestClient.getSeries(this.thing, this.propertyId, start, end, opts);
const times = result.responses[0].times;
const values = result.responses[0].values;
let data = [];
Expand Down Expand Up @@ -241,19 +248,19 @@ module.exports = function (RED) {
this.status({});
this.timeWindowCount = config.timeWindowCount;
this.timeWindowUnit = config.timeWindowUnit;
this.organization = config.organization;
if (connectionConfig && config.thing !== "" && config.thing !== "0" && config.property !== "" && config.property !== "0") {
try {
this.arduinoRestClient = await connectionManager.getClientHttp(connectionConfig);
if (this.arduinoRestClient){
this.arduinoRestClient.openConnections++;
if (config.thing !== "" && config.property !== "") {
this.organization = config.organization;
this.thing = config.thing;
this.propertyId = config.property;
this.propertyName = config.name;
const pollTime = this.timeWindowCount * this.timeWindowUnit;
if (pollTime !== null && pollTime !== "" && pollTime !== undefined && Number.isInteger(parseInt(pollTime)) && parseInt(pollTime) !== 0) {
this.poll(connectionConfig, pollTime);
this.poll(connectionConfig, pollTime, this.organization);
this.on('close', function (done) {
connectionManager.deleteClientHttp(connectionConfig.credentials.clientid).then(() => { done(); });
if (this.pollTimeoutPoll)
Expand Down Expand Up @@ -283,9 +290,13 @@ module.exports = function (RED) {
realConstructor.apply(this, [config]);
}
ArduinoIotInputPoll.prototype = {
poll: async function (connectionConfig, pollTime) {
poll: async function (connectionConfig, pollTime, organization) {
try {
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId);
const opts = {}
if (organization) {
opts.xOrganization = organization;
}
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId, opts);
this.send(
{
topic: property.name,
Expand All @@ -298,7 +309,7 @@ module.exports = function (RED) {
this.status({ fill: "grey", shape: "dot", text: s });
else
this.status({});
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime) }, pollTime * 1000);
this.pollTimeoutPoll = setTimeout(() => { this.poll(connectionConfig, pollTime, organization) }, pollTime * 1000);
} catch (err) {
if(err.response && err.response.res && err.response.request){
console.log('statusCode: '+ err.response.res.statusCode +'\n'+
Expand Down Expand Up @@ -336,9 +347,13 @@ module.exports = function (RED) {
this.thing = config.thing;
this.propertyId = config.property;
this.propertyName = config.name;
const opts = {}
if (this.organization) {
opts.xOrganization = this.organization;
}
node.on('input', async function () {
try{
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId);
const property = await this.arduinoRestClient.getProperty(this.thing, this.propertyId, opts);
this.send(
{
topic: property.name,
Expand Down
173 changes: 91 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading