UNPKG

node-red-contrib-tinkerforge

Version:
122 lines (115 loc) 3.65 kB
<!-- - Copyright 2017 IBM Corp. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <script type="text/x-red" data-template-name="TinkerForge Digital-Out"> <div class="form-row"> <label for="node-input-device"><i class="fa fa-tasks"></i> Device</label> <input type="text" id="node-input-device" > </div> <div class="form-row"> <label for="node-input-sensor"><i class="fa"></i> Sensor</label> <select id="node-input-sensor"></select> </div> <div class="form-row"> <label for="node-input-topic"><i class="fa"></i> Topic Prefix</label> <input type="text" id="node-input-topic" placeholder="digiOut"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Temperature"> </div> </script> <script type="text/x-red" data-help-name="TinkerForge Digital-Out"> <p>This node sets the outputs high or low based on the incoming message. It accepts 3 different input formats:</p> <ol> <li>An object with keys, 0,1,2,3: <pre> { "0": true, "1": false, "2": true, "3": false } </pre> if a key is missing the output defaults to false. </li> <li>An array of 0/1 or false/true: <pre>[1,0,1,0]</pre> </li> <li>A CSV string <pre>"1,0,1,0"</pre> </li> </ol> </script> <script type="text/javascript"> RED.nodes.registerType("TinkerForge Digital-Out",{ category: 'TinkerForge', defaults: { device: {type: "TinkerForgeConfig", required: true}, sensor: {required: true}, topic: {type: "string"}, name: {} }, outputs: 0, inputs: 1, label: function() { return this.name || "TinkerForge Digital Out 4"; }, paletteLabel: 'Ind Digital Out 4', color: 'gray', icon: 'tf.png', oneditprepare: function() { var node = this; if (node.device) { var key = $('#node-input-device').val(); $.getJSON('TinkerForge/' + key +"/sensors/" + 224, function(data){ $('#node-input-sensor').find('option').remove().end(); for (d in data) { $('<option/>',{ value: data[d].uid, text: data[d].uid + " - " + data[d].position }).appendTo('#node-input-sensor'); } if (node.sensor) { $('#node-input-sensor').val(node.sensor); } }); } else { console.log("no device"); } $('#node-input-device').change(function(){ var dev = $('#node-input-device').val(); if (dev) { var key = dev; $.getJSON('TinkerForge/' + key +"/sensors/" + 224, function(data){ $('#node-input-sensor').find('option').remove().end(); for (d in data) { $('<option/>',{ value: data[d].uid, text: data[d].uid + " - " + data[d].position }).appendTo('#node-input-sensor'); } if (node.sensor) { $('#node-input-sensor').val(node.sensor); } }); } else { console.log("no device"); } }); if (node.sensor) { $('#node-input-sensor').val(node.sensor); } } }); </script>