Skip to content

Commit 68ab194

Browse files
committed
fix mqtt subscription
1 parent b7dd2df commit 68ab194

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

arduino-cloud.html

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
ret['timeWindowCount'] = { value: 1, validate: validateTime };
2828
ret['timeWindowUnit'] = { value: '3600', required: true };
2929
}
30+
31+
if (nodeName === "property in"){
32+
ret['variableName'] = {value: ""};
33+
}
34+
3035
return ret;
3136
}
3237

@@ -47,13 +52,13 @@
4752
},
4853
paletteLabel: labelName,
4954
oneditprepare: function () {
50-
debugger;
55+
5156
if (this.connection && this.connection !== "_ADD_") {
5257
initThings(this.connection, this.thing);
5358
initProperties(this.connection, this.thing, this.property, outs);
5459
}
5560
$("select#node-input-connection").change((e) => {
56-
debugger;
61+
5762
const connection = $("#node-input-connection").val();
5863
const thing_id = $("#node-input-thing").val();
5964
if (connection === "_ADD_") {
@@ -76,7 +81,7 @@
7681
const property_id = $("#node-input-property").val();
7782
const connection = $("#node-input-connection").val();
7883
const thing_text = $("#node-input-thing").find('option:selected').text()
79-
debugger;
84+
8085
if (connection === "_ADD_") {
8186
$("select#node-input-property").empty();
8287
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-property");
@@ -90,15 +95,24 @@
9095
$("select#node-input-property").empty();
9196
initProperties(connection, thing_id, undefined, outs);
9297
}
93-
}
98+
}
9499
});
95100
$("#node-input-property").change(() => {
96101
const property_name = $("#node-input-property").find('option:selected').text();
97102
const property_value = $("#node-input-property").find('option:selected').val();
98-
debugger;
99-
if (property_name !== " " && property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) {
103+
var variablename_property;
104+
if(nodeName === 'property in'){
105+
variablename_property = $("#node-input-property").find('option:selected').attr("variablename");
106+
}
107+
108+
if (property_name !== " " && property_name !== "" && property_value !== "" && property_value !== undefined ) {
100109
this.propname = property_name;
101-
$("#node-input-name").val(property_name);
110+
if(nodeName === 'property in'){
111+
this.variableName = variablename_property;
112+
}
113+
if(this.defaultname){
114+
$("#node-input-name").val(property_name);
115+
}
102116
}
103117
$("#node-input-name").trigger("change");
104118
});
@@ -138,13 +152,12 @@
138152
}
139153
}
140154
function initThings(connection, thing_id) {
141-
debugger;
142155
const queryString = prepareQueryString(connection);
143156
if (!queryString || queryString === "")
144157
return;
145158

146159
$("select#node-input-thing").empty();
147-
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-thing");
160+
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-thing");
148161
$("select#node-input-thing").val("updating");
149162

150163
$.getJSON(`things?${queryString}`, things => {
@@ -172,7 +185,6 @@
172185
});
173186
}
174187
function initProperties(connection, thing_id, property_id, outs) {
175-
debugger;
176188
let queryString = prepareQueryString(connection);
177189
if (!queryString || queryString === "")
178190
return;
@@ -181,7 +193,7 @@
181193
queryString = `${queryString}&thing_id=${thing_id}`;
182194

183195
$("select#node-input-property").empty();
184-
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-property");
196+
$("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-property");
185197
$("select#node-input-property").val("updating");
186198

187199
$.getJSON(`properties?${queryString}`, properties => {
@@ -195,7 +207,7 @@
195207
$("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property");
196208
for (const p of properties) {
197209
if (outs > 0 || p.permission === "READ_WRITE")
198-
$("<option value='" + p.id + "'>" + p.name + "</option>").appendTo("#node-input-property");
210+
$("<option value='" + p.id + "' variablename='"+p.variable_name+"'>" + p.name + "</option>").appendTo("#node-input-property");
199211
}
200212
if (property_id !== undefined) {
201213
$("#node-input-property").val(property_id);

arduino-cloud.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ module.exports = function (RED) {
1414
this.thing = config.thing;
1515
this.propertyId = config.property;
1616
this.propertyName = config.propname;
17+
this.propertyVariableName = config.variableName;
1718
this.arduinoClient = await connectionManager.getClientMqtt(connectionConfig, RED);
1819
if (this.arduinoClient && this.arduinoClient.connection.connected) {
19-
await this.arduinoClient.onPropertyValue(this.thing, this.propertyName, (msg) => {
20+
await this.arduinoClient.onPropertyValue(this.thing, this.propertyVariableName, (msg) => {
2021
this.send(
2122
{
2223
topic: this.propertyName,

0 commit comments

Comments
 (0)