node-red-contrib-victron-ble
Version:
node-red node to parse Instant Readout advertisement data from Victron BLE devices
109 lines (102 loc) • 4.38 kB
HTML
<script type="text/javascript">;
RED.nodes.registerType('victron-ble', {
category: 'victron',
color: '#4790d0',
defaults: {
name: { value: "" },
address: { value: "", required: true },
key: { value: "", type: "text" },
includeRaw: { value: false }
},
credentials: {
key: { type: "text" }
},
inputs: 0,
outputs: 1,
icon: "victronenergy.svg",
paletteLabel: "BLE",
label: function () {
return this.name || "BLE";
},
oneditprepare() {
if (this.credentials.has_key)
$("#node-input-key").attr("placeholder", "**** Change existing Decryption Key ****");
var $discoverBtn = $("#node-victron-ble-discover");
$discoverBtn.on('click', () => {
$.getJSON('victron-ble/discover', function (devices) {
if (devices.length === 0) {
return;
}
const options_list = [];
devices.forEach(function (dev) {
options_list.push({ value: dev.address, label: dev.name + ' (' + dev.address + ')' });
});
$("#node-input-address").typedInput({
types: [
{
value: "",
options: options_list
}
]
});
});
});
},
oneditsave() {
const $inputKey = $('#node-input-key');
if ($inputKey.val() == "")
$inputKey.remove();
// Format MAC address if missing colons
const $inputAddress = $('#node-input-address');
let address = $inputAddress.val();
// Check for 12 hex digits, no colons
if (/^[0-9a-fA-F]{12}$/.test(address)) {
// Insert colons every 2 chars
address = address.replace(/(.{2})(?=.)/g, '$1:').toLocaleLowerCase();
$inputAddress.val(address);
}
}
});
</script>
<script type="text/javascript">
export {};
</script>
<script type="text/script" data-template-name="victron-ble">
<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="Name">
</div>
<div class="form-row">
<label for="node-input-address"><i class="fa fa-bluetooth"></i>Device</label>
<input type="text" id="node-input-address" placeholder="Device Address (XX:XX:XX:XX:XX:XX)">
<button id="node-victron-ble-discover" type="button" class="red-ui-button"
style="padding-right: 5px;padding-left: 5px;color: black !important;border: 0px;"
title="Discover Devices"><i class="fa fa-search"></i></button>
</div>
<div class="form-row">
<label for="node-input-key"><i class="fa fa-key"></i>Key</label>
<input type="password" id="node-input-key" placeholder="Decryption Key">
</div>
<div class="form-row">
<label for="node-input-includeRaw"><i class="fa fa-code"></i>Include Raw Data</label>
<input type="checkbox" id="node-input-includeRaw" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-includeRaw" style="width: 70%;">Include raw decrypted data as parseDecrypted in payload</label>
</div>
</script>
<script type="text/script" data-help-name="victron-ble">
<p>Node-RED node for reading Victron BLE device data.</p>
<p>Use the <b>Discover Devices</b> button to scan for nearby Victron devices. Select a device and enter its decryption key to read data.</p>
<ul>
<li><b>Device Address</b>: The BLE address of the device (select from discovered devices or enter manually).</li>
<li><b>Decryption Key</b>: The key required to decrypt the device's data.</li>
</ul>
<p><b>Output:</b> Emits a message for each successfully decoded packet with the following properties:</p>
<ul>
<li><b>payload</b>: The parsed device data</li>
<li><b>address</b>: The device address</li>
<li><b>name</b>: The device name</li>
<li><b>rssi</b>: Signal strength</li>
</ul>
<p><b>Include Raw Data:</b> When enabled, adds a <code>parseDecrypted</code> property to the payload containing the raw decrypted hex data.</p>
</script>