UNPKG

node-red-contrib-blynk-ws

Version:

Node Red integration with Blynk App and Server through websockets

104 lines (96 loc) 3.96 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; } 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 (validPin(this.pin)) { pin = `Pin V${this.pin} - ${type}`; } if (allpin) { pin = `Pin All - ${type}`; } return this.name || pin; } RED.nodes.registerType('blynk-ws-out-sync', { category: 'Blynk_ws', paletteLabel: 'sync', defaults: { name: { value: '' }, pin: { value: '', required: false, validate: RED.validators.regex(/^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$/) }, pinmode: { value: 0 }, client: { type: 'blynk-ws-client', required: true }, }, color: '#1BC17C', 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-ws-out-sync"> <div class="form-row" id="websocket-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="number" id="node-input-pin" min="0" max="255" 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-ws-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<br> &nbsp;&nbsp; syncVirtual, select the pin number in the interface<br> &nbsp;&nbsp; syncAll, request the sync of all pins</p> <p class="form-tips"> Official documentation: <a href="https://gablau.dev/blynk-legacy-docs/#blynk-main-operations-state-syncing-for-hardware">State syncing</a> <a href="https://gablau.dev/blynk-legacy-docs/#blynk-firmware-blynktimer-blynksyncall">Blynk.syncAll()</a> <a href="https://gablau.dev/blynk-legacy-docs/#blynk-firmware-blynktimer-blynksyncvirtualvpin">Blynk.syncVirtual()</a> <p> </script>