node-red-contrib-blynk-ws
Version:
Node Red integration with Blynk App and Server through websockets
118 lines (104 loc) • 4.21 kB
HTML
<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 onEditPrepare() {
$('#node-input-pin_all').on('change', () => {
if ($(this).is(':checked')) {
$('#div-input-pin').hide();
} else {
$('#div-input-pin').show();
}
}).change();
}
function onEditSave() {
if ($('#node-input-pin_all').val() == 1) { // eslint-disable-line eqeqeq
if (!validPin($('#node-input-pin').val())) {
$('#node-input-pin').val('0');
}
}
}
function label() {
let pin = 'pin error';
const type = 'Write Event';
if (validPin(this.pin)) {
pin = `Pin V${this.pin} - ${type}`;
}
if (this.pin_all) {
pin = `All Pins - ${type}`;
}
return this.name || pin;
}
RED.nodes.registerType('blynk-ws-in-write', {
category: 'Blynk_ws',
paletteLabel: 'write event',
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])$/) },
pin_all: { value: 0 },
client: { type: 'blynk-ws-client', required: true },
},
color: '#1BC17C',
inputs: 0,
outputs: 1,
icon: 'white-globe.png',
labelStyle() {
return this.name ? 'node_label_italic' : '';
},
label,
oneditsave: onEditSave,
oneditprepare: onEditPrepare,
});
}());
</script>
<!-- Blynk Input Node - Write -->
<script type="text/x-red" data-template-name="blynk-ws-in-write">
<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-pin_all"><i class="fa fa-cogs"></i> <span>Virtual Pin</span></label>
<input type="checkbox" id="node-input-pin_all" value="1" style="width: auto; vertical-align: top;"> All Pins</span></input>
</div>
<div id="div-input-pin" class="form-row">
<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-in-write">
<p>Blynk write event node.</p>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>the value sent from the specified pin.</dd>
<dt>pin <span class="property-type">string</span></dt>
<dd>the pin number that fire this event.</dd>
<dt>arrayOfValues <span class="property-type">array</span></dt>
<dd>an array of values sent, useful for Widgets that have the MERGE ability.</dd>
</dl>
</li>
</ol>
<!--
<h3>Details</h3>
<p><code>msg.payload</code> is used as the payload of the published message.</p>
-->
<h3>References</h3>
<ul>
<li>Official documentation - <a href="https://gablau.dev/blynk-legacy-docs/#blynk-main-operations-send-data-from-app-to-hardware">Write</a></li>
<li><a href="https://github.com/gablau/node-red-contrib-blynk-ws">GitHub</a> - the nodes github repository</li>
<li><a href="https://www.npmjs.com/package/node-red-contrib-blynk-ws">NPM</a> - the nodes on package manager</li>
</ul>
</script>