UNPKG

node-red-contrib-blynk-iot

Version:
106 lines (98 loc) 3.9 kB
<script type="text/javascript"> // eslint-disable-next-line func-names (function () { function validPin(tmppin) { /* const tmpPin = parseInt(tmppin, 10); if (Number.isInteger(tmpPin) && tmpPin >= 0 && tmpPin <= 255) { return true; } return false; */ return true; } function onEditSave() { if ($('#node-input-pinmode').val() == 1) { // eslint-disable-line eqeqeq if (!validPin($('#node-input-pin').val())) { $('#node-input-pin').val('0'); } } } function onEditPrepare() { $('#node-input-pinmode').on('change', function onChangePinMode() { if ($(this).val() == 0) { // eslint-disable-line eqeqeq $('#div-sync-pin').show(); } else { $('#div-sync-pin').hide(); } }).change(); } function label() { let pin = 'pin error'; const type = 'Sync'; const allpin = (this.pinmode == 1); // eslint-disable-line eqeqeq if (allpin) { pin = `Pin All - ${type}`; } else { pin = `Pin V${this.pin} - ${type}`; } return this.name || pin; } RED.nodes.registerType('blynk-iot-out-sync', { category: 'Blynk IoT', paletteLabel: 'sync', defaults: { name: { value: '' }, pin: { value: '', required: false }, pinmode: { value: 0 }, client: { type: 'blynk-iot-client', required: true }, }, color: '#8be8c8', inputs: 1, outputs: 0, icon: 'sync.png', align: 'right', labelStyle() { return this.name ? 'node_label_italic' : ''; }, label, oneditsave: onEditSave, oneditprepare: onEditPrepare, }); }()); </script> <!-- Blynk out Node - sync --> <script type="text/x-red" data-template-name="blynk-iot-out-sync"> <div class="form-row" id="client-row"> <label for="node-input-client"><i class="fa fa-bookmark"></i> <span>Connection</span></label> <input type="text" id="node-input-client"> </div> <div class="form-row"> <label for="node-input-pinmode"><i class="fa fa-cogs"></i> <span>Sync Mode</span></label> <select id="node-input-pinmode" style="width:70%"> <option value="0">syncVirtual</option> <option value="1">syncAll</option> </select> </div> <div class="form-row" id="div-sync-pin"> <label for="node-input-pin"><i class="fa fa-dot-circle-o"></i> <span>Virtual Pin</span></label> <input type="text" id="node-input-pin" placeholder="pin"> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label> <input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name"> </div> </script> <script type="text/x-red" data-help-name="blynk-iot-out-sync"> <p>Blynk sync node.</p> <p>This node will request server to send the most recent value of all pins or a single pin. Every virtual pin will generate a write event.</p><br> <p>"Sync mode" choose if you want to sync all the pins or just a specific pin/pins<br> &nbsp;&nbsp; syncVirtual, select the pin number in the interface, separate multiple pins by comma. Ex.(1,2,3)<br> &nbsp;&nbsp; syncAll, request the sync of all pins </p> <p class="form-tips"> Official documentation: <a href="https://docs.blynk.io/en/blynk.edgent-firmware-api/state-syncing">State Syncing()</a> <a href="https://docs.blynk.io/en/blynk.edgent-firmware-api/virtual-pins#blynk.syncall">Blynk.syncAll()</a> <a href="https://docs.blynk.io/en/blynk.edgent-firmware-api/virtual-pins#blynk.syncvirtual-vpin">Blynk.syncVirtual()</a> <p> </script>