|
4 | 4 | function validator(v) { |
5 | 5 | return (v !== null && v !== "" && v !== undefined); |
6 | 6 | } |
7 | | - function setupNode(nodeName, ins, outs) { |
8 | | - RED.nodes.registerType(nodeName, { |
9 | | - category: 'Arduino IoT Cloud', |
10 | | - color: '#00979d', |
11 | | - defaults: { |
12 | | - connection: { type: "arduino-connection", validate: validator }, |
| 7 | + |
| 8 | + function getDefaults(nodeName){ |
| 9 | + var ret={connection: { type: "arduino-connection", validate: validator }, |
13 | 10 | thing: { value: "", validate: validator }, |
14 | 11 | property: { value: "", validate: validator }, |
15 | 12 | name: { value: "", validate: validator }, |
16 | 13 | propname: { value: "" }, |
17 | 14 | prevconnection: { value: "" } |
18 | | - }, |
| 15 | + }; |
| 16 | + |
| 17 | + if (nodeName === "property in hist" || nodeName === "property in poll"){ |
| 18 | + ret['timeWindowCount'] = { value: 1, validate: RED.validators.number(), required: true }; |
| 19 | + ret['timeWindowUnit'] = { value: '3600', required: true }; |
| 20 | + } |
| 21 | + return ret; |
| 22 | + } |
| 23 | + |
| 24 | + function getName(nodeName){ |
| 25 | + var ret; |
| 26 | + switch (nodeName){ |
| 27 | + case 'property in': |
| 28 | + case 'property out': |
| 29 | + ret='property'; |
| 30 | + break; |
| 31 | + case 'property in hist': |
| 32 | + ret='historic'; |
| 33 | + break; |
| 34 | + case 'property in poll': |
| 35 | + ret ='periodic'; |
| 36 | + break; |
| 37 | + case 'property in push': |
| 38 | + ret = 'inject'; |
| 39 | + break; |
| 40 | + |
| 41 | + } |
| 42 | + return ret; |
| 43 | + } |
| 44 | + |
| 45 | + function setupNode(nodeName, ins, outs) { |
| 46 | + var defaults = getDefaults(nodeName); |
| 47 | + var name = getName(nodeName); |
| 48 | + RED.nodes.registerType(nodeName, { |
| 49 | + category: 'Arduino IoT Cloud', |
| 50 | + color: '#00979d', |
| 51 | + defaults: defaults, |
19 | 52 | inputs: ins, |
20 | 53 | outputs: outs, |
21 | 54 | icon: "arduino.png", |
22 | 55 | label: function () { |
23 | | - return this.name || nodeName; |
| 56 | + return this.name || name; |
24 | 57 | }, |
| 58 | + paletteLabel: name, |
25 | 59 | oneditprepare: function () { |
26 | 60 | if (this.connection && this.connection !== "_ADD_") { |
27 | 61 | initThings(this.connection, this.thing); |
|
35 | 69 | if (connectionTmp) |
36 | 70 | connectionTmp.isUpdatedConnection = false; |
37 | 71 | this.prevconnection = connection; |
38 | | - this.connection = connection; |
39 | 72 | $("select#node-input-thing").empty(); |
40 | 73 | $("select#node-input-property").empty(); |
41 | 74 | $("#node-input-name").val(""); |
|
44 | 77 | this.propname = ""; |
45 | 78 | this.name = ""; |
46 | 79 | if (connection !== "_ADD_") { |
47 | | - initThings(this.connection, this.thing); |
| 80 | + initThings(connection, this.thing); |
48 | 81 | } |
49 | 82 | $("#node-input-thing").trigger("change"); |
50 | 83 | }); |
51 | 84 | $("#node-input-thing").change(() => { |
52 | 85 |
|
53 | 86 | const thing_id = $("#node-input-thing").val(); |
54 | | - if (thing_id) { |
55 | | - initProperties(this.connection, thing_id, undefined, outs); |
| 87 | + if (thing_id && thing_id !== "0") { |
| 88 | + const connection = $("#node-input-connection").val(); |
| 89 | + initProperties(connection, thing_id, undefined, outs); |
56 | 90 | } else { |
57 | 91 | $("select#node-input-property").empty(); |
58 | 92 | } |
|
61 | 95 | $("#node-input-property").change(() => { |
62 | 96 | const property_name = $("#node-input-property").find('option:selected').text(); |
63 | 97 | const property_value = $("#node-input-property").find('option:selected').val(); |
64 | | - if (property_name !== "" && property_value !== "" && property_value !== undefined) { |
| 98 | + if (property_name !== "" && property_value !== "" && property_value !== undefined && this.propname === "") { |
65 | 99 | this.propname = property_name; |
66 | 100 | $("#node-input-name").val(property_name); |
67 | 101 | } |
|
74 | 108 | } |
75 | 109 | }); |
76 | 110 | } |
| 111 | + |
77 | 112 | setupNode("property in", 0, 1); |
78 | 113 | setupNode("property out", 1, 0); |
79 | | - |
| 114 | + setupNode("property in hist", 1, 1);//historic |
| 115 | + setupNode("property in poll", 0, 1);//periodic |
| 116 | + setupNode("property in push", 1, 1);//inject |
80 | 117 | </script> |
| 118 | + |
| 119 | + |
81 | 120 | <script type="text/x-red" data-template-name="property in"> |
82 | 121 | <div class="form-row node-input-connection"> |
83 | 122 | <label for="node-input-connection"><i class="fa fa-random"></i> Connection</label> |
|
150 | 189 | } |
151 | 190 | if (thing_id !== undefined) { |
152 | 191 | $("#node-input-thing").val(thing_id); |
153 | | - $("#node-input-property").val(""); |
154 | 192 | } |
155 | 193 | $("#node-input-property").trigger("change"); |
156 | 194 | } |
|
234 | 272 | </script> |
235 | 273 |
|
236 | 274 |
|
237 | | -<script type="text/javascript"> |
238 | | - RED.nodes.registerType('property in hist', { |
239 | | - category: 'Arduino IoT Cloud', |
240 | | - color: '#00979d', |
241 | | - defaults: { |
242 | | - connection: { type: "arduino-connection", validate: validator }, |
243 | | - thing: { value: "", validate: validator }, |
244 | | - property: { value: "", validate: validator }, |
245 | | - propid: { value: "" }, |
246 | | - name: { value: "", validate: validator }, |
247 | | - timeWindowCount: { value: 1, validate: RED.validators.number(), required: true }, |
248 | | - timeWindowUnit: { value: '3600', required: true }, |
249 | | - prevconnection: { value: "" }, |
250 | | - propname: { value: "" } |
251 | | - }, |
252 | | - inputs: 1, |
253 | | - outputs: 1, |
254 | | - icon: "arduino.png", |
255 | | - label: function () { |
256 | | - return this.name || "historic"; |
257 | | - }, |
258 | | - paletteLabel: "historic", |
259 | | - oneditprepare: function () { |
260 | | - debugger; |
261 | | - console.log("thing_id: " + this.thing); |
262 | | - console.log("property_id: " + this.property); |
263 | | - if (this.connection && this.connection !== "_ADD_") { |
264 | | - initThings(this.connection, this.thing); |
265 | | - initProperties(this.connection, this.thing, this.property, 1); |
266 | | - } |
267 | | - $("select#node-input-connection").change(() => { |
268 | | - const connection = $("#node-input-connection").val(); |
269 | | - const connectionTmp = window.connectionManager[connection]; |
270 | | - const isUpdatedConnection = connectionTmp ? connectionTmp.isUpdatedConnection : false; |
271 | | - if (connection == this.prevconnection && isUpdatedConnection === false) return; |
272 | | - if (connectionTmp) |
273 | | - connectionTmp.isUpdatedConnection = false; |
274 | | - this.prevconnection = connection; |
275 | | - this.connection = connection; |
276 | | - $("select#node-input-thing").empty(); |
277 | | - $("select#node-input-property").empty(); |
278 | | - $("#node-input-name").val(""); |
279 | | - this.thing = ""; |
280 | | - this.property = ""; |
281 | | - this.propname = ""; |
282 | | - this.name = ""; |
283 | | - if (connection !== "_ADD_") { |
284 | | - initThings(this.connection, this.thing); |
285 | | - } |
286 | | - $("#node-input-thing").trigger("change"); |
287 | | - }); |
288 | | - $("#node-input-thing").change(() => { |
289 | | - const thing_id = $("#node-input-thing").val(); |
290 | | - if (thing_id && thing_id !== "0") { |
291 | | - initProperties(this.connection, thing_id, undefined, 1); |
292 | | - } else { |
293 | | - $("select#node-input-property").empty(); |
294 | | - } |
295 | | - $("#node-input-property").trigger("change"); |
296 | | - }); |
297 | | - $("#node-input-property").change(() => { |
298 | | - const property_name = $("#node-input-property").find('option:selected').text(); |
299 | | - const property_value = $("#node-input-property").find('option:selected').val(); |
300 | | - if (property_name !== "" && property_value !== "" && property_value !== undefined) { |
301 | | - this.propname = property_name; |
302 | | - $("#node-input-name").val(property_name); |
303 | | - } |
304 | | - $("#node-input-name").trigger("change"); |
305 | | - }); |
306 | | - }, |
307 | | - oneditsave: function () { |
308 | | - console.log("thing_id: " + this.thing); |
309 | | - console.log("property_id: " + this.property); |
310 | | - } |
311 | | - }); |
312 | | -</script> |
313 | | - |
314 | 275 | <script type="text/x-red" data-template-name="property in hist"> |
315 | 276 | <div class="form-row node-input-connection"> |
316 | 277 | <label for="node-input-connection"><i class="fa fa-random"></i> Connection</label> |
|
349 | 310 | <p>This node injects in the flow a set of values of an Arduino Cloud Property based on the node configuration.</p> |
350 | 311 | </script> |
351 | 312 |
|
352 | | -<script type="text/javascript"> |
353 | | - RED.nodes.registerType('property in poll', { |
354 | | - category: 'Arduino IoT Cloud', |
355 | | - color: '#00979d', |
356 | | - defaults: { |
357 | | - connection: { type: "arduino-connection", validate: validator }, |
358 | | - thing: { value: "", validate: validator }, |
359 | | - property: { value: "", validate: validator }, |
360 | | - propid: { value: "" }, |
361 | | - name: { value: "", validate: validator }, |
362 | | - timeWindowCount: { value: 1, validate: RED.validators.number(), required: true }, |
363 | | - timeWindowUnit: { value: '3600', required: true }, |
364 | | - prevconnection: { value: "" }, |
365 | | - propname: { value: "" }, |
366 | | - }, |
367 | | - inputs: 0, |
368 | | - outputs: 1, |
369 | | - icon: "arduino.png", |
370 | | - label: function () { |
371 | | - return this.name || "periodic"; |
372 | | - }, |
373 | | - paletteLabel: "periodic", |
374 | | - oneditprepare: function () { |
375 | | - console.log("thing_id: " + this.thing); |
376 | | - console.log("property_id: " + this.property); |
377 | | - if (this.connection && this.connection !== "_ADD_") { |
378 | | - initThings(this.connection, this.thing); |
379 | | - initProperties(this.connection, this.thing, this.property, 1); |
380 | | - } |
381 | | - $("select#node-input-connection").change(() => { |
382 | | - const connection = $("#node-input-connection").val(); |
383 | | - const connectionTmp = window.connectionManager[connection]; |
384 | | - const isUpdatedConnection = connectionTmp ? connectionTmp.isUpdatedConnection : false; |
385 | | - if (connection == this.prevconnection && isUpdatedConnection === false) return; |
386 | | - if (connectionTmp) |
387 | | - connectionTmp.isUpdatedConnection = false; |
388 | | - this.prevconnection = connection; |
389 | | - this.connection = connection; |
390 | | - $("select#node-input-thing").empty(); |
391 | | - $("select#node-input-property").empty(); |
392 | | - $("#node-input-name").val(""); |
393 | | - this.thing = ""; |
394 | | - this.property = ""; |
395 | | - this.propname = ""; |
396 | | - this.name = ""; |
397 | | - if (connection !== "_ADD_") { |
398 | | - initThings(this.connection, this.thing); |
399 | | - } |
400 | | - $("#node-input-thing").trigger("change"); |
401 | | - }); |
402 | | - $("#node-input-thing").change(() => { |
403 | | - const thing_id = $("#node-input-thing").val(); |
404 | | - if (thing_id && thing_id !== "0") { |
405 | | - initProperties(this.connection, thing_id, undefined, 1); |
406 | | - } else { |
407 | | - $("select#node-input-property").empty(); |
408 | | - } |
409 | | - $("#node-input-property").trigger("change"); |
410 | | - }); |
411 | | - $("#node-input-property").change(() => { |
412 | | - const property_name = $("#node-input-property").find('option:selected').text(); |
413 | | - const property_value = $("#node-input-property").find('option:selected').val(); |
414 | | - if (property_name !== "" && property_value !== "" && property_value !== undefined) { |
415 | | - this.propname = property_name; |
416 | | - $("#node-input-name").val(property_name); |
417 | | - } |
418 | | - $("#node-input-name").trigger("change"); |
419 | | - }); |
420 | | - }, |
421 | | - oneditsave: function () { |
422 | | - console.log("thing_id: " + this.thing); |
423 | | - console.log("property_id: " + this.property); |
424 | | - } |
425 | | - }); |
426 | | -</script> |
427 | | - |
428 | 313 | <script type="text/x-red" data-template-name="property in poll"> |
429 | 314 | <div class="form-row node-input-connection"> |
430 | 315 | <label for="node-input-connection"><i class="fa fa-random"></i> Connection</label> |
|
462 | 347 | <p>This node injects in the flow the value of an Arduino Cloud Property with a periodicity based on the node configuration.</p> |
463 | 348 | </script> |
464 | 349 |
|
465 | | -<script type="text/javascript"> |
466 | | - RED.nodes.registerType('property in push', { |
467 | | - category: 'Arduino IoT Cloud', |
468 | | - color: '#00979d', |
469 | | - defaults: { |
470 | | - connection: { type: "arduino-connection", validate: validator }, |
471 | | - thing: { value: "", validate: validator }, |
472 | | - property: { value: "", validate: validator }, |
473 | | - propid: { value: "" }, |
474 | | - name: { value: "", validate: validator }, |
475 | | - prevconnection: { value: "" }, |
476 | | - propname: { value: "" } |
477 | | - }, |
478 | | - inputs: 1, |
479 | | - outputs: 1, |
480 | | - icon: "arduino.png", |
481 | | - label: function () { |
482 | | - return this.name || "inject"; |
483 | | - }, |
484 | | - paletteLabel: "inject", |
485 | | - oneditprepare: function () { |
486 | | - console.log("thing_id: " + this.thing); |
487 | | - console.log("property_id: " + this.property); |
488 | | - if (this.connection && this.connection !== "_ADD_") { |
489 | | - initThings(this.connection, this.thing); |
490 | | - initProperties(this.connection, this.thing, this.property, 1); |
491 | | - } |
492 | | - $("select#node-input-connection").change(() => { |
493 | | - const connection = $("#node-input-connection").val(); |
494 | | - const connectionTmp = window.connectionManager[connection]; |
495 | | - const isUpdatedConnection = connectionTmp ? connectionTmp.isUpdatedConnection : false; |
496 | | - if (connection == this.prevconnection && isUpdatedConnection === false) return; |
497 | | - if (connectionTmp) |
498 | | - connectionTmp.isUpdatedConnection = false; |
499 | | - this.prevconnection = connection; |
500 | | - this.connection = connection; |
501 | | - $("select#node-input-thing").empty(); |
502 | | - $("select#node-input-property").empty(); |
503 | | - $("#node-input-name").val(""); |
504 | | - this.thing = ""; |
505 | | - this.property = ""; |
506 | | - this.propname = ""; |
507 | | - this.name = ""; |
508 | | - if (connection !== "_ADD_") { |
509 | | - initThings(this.connection, this.thing); |
510 | | - } |
511 | | - $("#node-input-thing").trigger("change"); |
512 | | - }); |
513 | | - $("#node-input-thing").change(() => { |
514 | | - const thing_id = $("#node-input-thing").val(); |
515 | | - if (thing_id && thing_id !== "0") { |
516 | | - initProperties(this.connection, thing_id, undefined, 1); |
517 | | - } else { |
518 | | - $("select#node-input-property").empty(); |
519 | | - } |
520 | | - $("#node-input-property").trigger("change"); |
521 | | - }); |
522 | | - $("#node-input-property").change(() => { |
523 | | - const property_name = $("#node-input-property").find('option:selected').text(); |
524 | | - const property_value = $("#node-input-property").find('option:selected').val(); |
525 | | - if (property_name !== "" && property_value !== "" && property_value !== undefined) { |
526 | | - this.propname = property_name; |
527 | | - $("#node-input-name").val(property_name); |
528 | | - } |
529 | | - $("#node-input-name").trigger("change"); |
530 | | - }); |
531 | | - }, |
532 | | - oneditsave: function () { |
533 | | - console.log("thing_id: " + this.thing); |
534 | | - console.log("property_id: " + this.property); |
535 | | - } |
536 | | - }); |
537 | | -</script> |
538 | 350 |
|
539 | 351 | <script type="text/x-red" data-template-name="property in push"> |
540 | 352 | <div class="form-row node-input-connection"> |
|
0 commit comments