UNPKG

node-red-contrib-lorawan

Version:

Node-RED module for the LoRaWAN RN2483 and RN2903 radio modules

285 lines (273 loc) 11.3 kB
<script type="text/javascript"> RED.nodes.registerType('lorawan-rx', { category: 'iot', color: '#FFFFFF', defaults: { name: { value: '' }, loraWAN: { value: '', type: 'lorawan-config' } }, inputs: 0, outputs: 1, icon: 'lorawan.png', label: function () { return this.name || 'LoRaWAN RX'; }, paletteLabel: 'LoRaWAN RX' }); RED.nodes.registerType('lorawan-tx', { category: 'iot', color: '#FFFFFF', defaults: { name: { value: '' }, loraWAN: { value: '', type: "lorawan-config" } }, inputs: 1, outputs: 0, icon: 'lorawan.png', align: 'right', label: function () { return this.name || 'LoRaWAN TX'; }, paletteLabel: 'LoRaWAN TX' }); RED.nodes.registerType('lorawan-config', { category: 'config', defaults: { rawFrames: { value: false, required: true }, mode: { value: '2', required: true }, modeP2P_radioPwr: { value: 15, required: true}, modeP2P_radioFreq: { value: 868100000, required: true}, modeP2P_radioSf: { value: 'sf12', required: true}, modeP2P_radioCr: { value: '4/5', required: true}, modeP2P_radioBw: { value: 125, required: true}, modeP2P_radioCRC: { value: 'on', required: true}, serialPort: { value: '', required: true }, lock: { value: true, required: true }, baudRate: { value: 57600, required: true }, dataBits: { value: 8, required: true }, stopBits: { value: 1, required: true }, parity: { value: 'none', required: true }, }, label: function () { return '('+this.id+') LoRaWAN[api:' + this.mode + ']@' + this.serialPort + ':' + this.baudRate; }, oneditprepare: function () { var node = this; var buildOptionsHtml = function (propertyName, actualValue, options) { for (i = 0; i < options.length; i++) { $('#node-config-input-' + propertyName).append( '<option value=' + options[i] + ((actualValue == options[i]) ? ' selected>' : '>') + options[i] + '</option>'); } } var baudRates = [ 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 ]; var modes = [ <!-- { name: 'Standard', value: '1' }, --> { name: 'P2P', value: '2' } ]; var dataBits = [8, 7, 6, 5]; var stopBits = [1, 2]; var parity = ['none', 'even', 'mark', 'odd', 'space']; var power = [ -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; var spreadingFactor = ['sf7', 'sf8', 'sf9', 'sf10', 'sf11', 'sf12']; var codingRate = ['4/5', '4/6', '4/7', '4/8']; var bandWidth = [125, 250, 500]; var crc = ['on', 'off']; buildOptionsHtml('baudRate', node.baudRate, baudRates); buildOptionsHtml('dataBits', node.dataBits, dataBits); buildOptionsHtml('stopBits', node.stopBits, stopBits); buildOptionsHtml('parity', node.parity, parity); buildOptionsHtml('modeP2P_radioPwr', node.modeP2P_radioPwr, power); buildOptionsHtml('modeP2P_radioSf', node.modeP2P_radioSf, spreadingFactor); buildOptionsHtml('modeP2P_radioCr', node.modeP2P_radioCr, codingRate); buildOptionsHtml('modeP2P_radioBw', node.modeP2P_radioBw, bandWidth); buildOptionsHtml('modeP2P_radioCRC', node.modeP2P_radioCRC, crc); for (i = 0; i < modes.length; i++) { $('#node-config-input-mode') .append( '<option value=' + modes[i].value + ((node.mode == modes[i].value) ? ' selected>' : '>') + modes[i].name + '</option>'); } $("#node-config-lookup-serial").click(function() { $("#node-config-lookup-serial").addClass('disabled'); $.getJSON('serialports',function(data) { $("#node-config-lookup-serial").removeClass('disabled'); var ports = []; $.each(data, function(i, port) { ports.push(port.comName); }); $("#node-config-input-serialPort").autocomplete({ source:ports, minLength:0, close: function( event, ui ) { $("#node-config-input-serialPort").autocomplete( "destroy" ); } }).autocomplete("search",""); }); }); } }); </script> <script type="text/x-red" data-template-name="lorawan-rx"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name TX</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-loraWAN"><i class="fa fa-cog"></i> LoRaWAN</label> <input type="text" id="node-input-loraWAN" placeholder="Serial Port"> </div> </script> <script type="text/x-red" data-help-name="lorawan-rx"> <p>LoRaWAN node is intended to Continuously Receive Data</p> <h3>Outputs</h3> <ol class="node-ports"> <li>Standard output <dl class="message-properties"> <dt>payload <span class="property-type">JSON object</span></dt> <dd>JSON Object containing the data frame received by LoRaWAN</dd> </dl> </li> </ol> <h3>Details</h3> <p>Once properly configured, this node will "listen" for incomming data frames, each data frame is delivered in the output node <code>msg.payload</code> message. </p> <h3>References</h3> <ul> <li><a href="https://github.com/EmergingTechnologyAdvisors/node-serialport">SerialPort</a> - Node.js package to access serial ports for reading and writing</li> </ul> </script> <script type="text/x-red" data-template-name="lorawan-tx"> <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-loraWAN"><i class="fa fa-cog"></i> LoRaWAN</label> <input type="text" id="node-input-loraWAN" placeholder="Serial Port"> </div> </script> <script type="text/x-red" data-help-name="lorawan-tx"> <p>LoRaWAN node is intended to Transmit Data</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">JSON Object</span> </dt> <dd>it expects a JSON Object in payload with the contents of the data frame to build</dd> </dl> <h3>Details</h3> <p>Once properly configured, this node will be ready to build and send data frames as they are received in the input node <code>msg.payload</code> </p> <!-- <h4>Example</h4> --> <!-- <p> --> <!-- To send a <i>0x10: ZigBee Transmit Request</i>, then build the following JSON object and copy it to the <code>msg.payload</code> which this node can use to build and deliver the message --> <!-- <pre> --> <!-- var myDataFrame = { --> <!-- type: 0x10, --> <!-- id: 0x01, --> <!-- destination64: "0013a200400a0127", --> <!-- destination16: "fffe", --> <!-- broadcastRadius: 0x00, --> <!-- options: 0x00, --> <!-- data: "Hello from Node-RED!" --> <!-- }; --> <!-- </pre> --> <!-- </p> --> <h3>References</h3> <ul> <li><a href="https://github.com/EmergingTechnologyAdvisors/node-serialport">SerialPort</a> - Node.js package to access serial ports for reading and writing</li> </ul> </script> <script type="text/x-red" data-template-name="lorawan-config"> <div class="form-row"> <h5>LoRaWAN</h5> <label for="node-config-input-rawFrames"><i class="fa fa-minus"></i> RAW Frames</label> <input type="checkbox" id="node-config-input-rawFrames" style="display: inline-block; width: auto; vertical-align: top;"> </div> <div class="form-row"> <label for="node-config-input-mode"><i class="fa fa-code"></i> API Mode</label> <select id="node-config-input-mode"></select> </div> <div class="form-row"> <label><i class="fa fa-wrench"></i> Settings</label> <label for="node-config-input-modeP2P_radioPwr"> Power</label> <select id="node-config-input-modeP2P_radioPwr" style="width:auto;"></select> </div> <div class="form-row"> <label>&nbsp;</label> <label for="node-config-input-modeP2P_radioFreq"> Frequency</label> <input type="number" id="node-config-input-modeP2P_radioFreq" style="width:auto;"> </div> <div class="form-row"> <label>&nbsp;</label> <label for="node-config-input-modeP2P_radioSf"> Spreading Factor</label> <select id="node-config-input-modeP2P_radioSf" style="width:auto;"></select> </div> <div class="form-row"> <label>&nbsp;</label> <label for="node-config-input-modeP2P_radioCr"> Coding Rate</label> <select id="node-config-input-modeP2P_radioCr" style="width:auto;"></select> </div> <div class="form-row"> <label>&nbsp;</label> <label for="node-config-input-modeP2P_radioBw"> Bandwidth</label> <select id="node-config-input-modeP2P_radioBw" style="width:auto;"></select> </div> <div class="form-row"> <label>&nbsp;</label> <label for="node-config-input-modeP2P_radioCRC"> CRC</label> <select id="node-config-input-modeP2P_radioCRC" style="width:auto;"></select> </div> <div class="form-row"> <h5>Serial Port</h5> <label for="node-config-input-serialPort"><i class="fa fa-random"></i> Serial Port</label> <input type="text" id="node-config-input-serialPort" style="width:auto;"> <a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a> </div> <div class="form-row"> <label>&nbsp;</label> <input type="checkbox" id="node-config-input-lock" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-config-input-lock" style="width: 70%;">Lock port (<em>not currently supported on windows</em>)</label> </div> <div class="form-row"> <table width="100%"> <tr> <td width="100px"><label><i class="fa fa-wrench"></i> Settings</label></td> <td width="110px"><label for="node-config-input-baudRate">Baud Rate</label></td> <td width="70px"><label for="node-config-input-dataBits">Data Bits</label></td> <td width="80px"><label for="node-config-input-parity">Parity</label></td> <td width="70px"><label for="node-config-input-stopBits">Stop Bits</label></td> </tr> <tr> <td>&nbsp;</td> <td><select id="node-config-input-baudRate" style="width:92%"></select></td> <td><select id="node-config-input-dataBits" style="width:90%;"></select></td> <td><select id="node-config-input-parity" style="width:90%;"></select></td> <td><select id="node-config-input-stopBits" style="width:90%;"></select></td> </tr> </table> </div> </script> <script type="text/x-red" data-help-name="lorawan-config"> <p>LoRaWAN configuration node, to be used by LoRaWAN nodes</p> <h3>Details</h3> <p>Except from the Serial Port, all other properties are configured with default values as indicated in <a href="https://github.com/EmergingTechnologyAdvisors/node-serialport">SerialPort</a> libraries. </p> <h3>References</h3> <ul> <li><a href="https://github.com/EmergingTechnologyAdvisors/node-serialport">SerialPort</a> - Node.js package to access serial ports for reading and writing</li> </ul> </script>