UNPKG

smithtek-node-red-lora

Version:

NodeRED nodes.

317 lines (268 loc) 13.1 kB
<script type="text/javascript"> RED.nodes.registerType('loraconfig', { category: 'Smithtek', color: '#B9B6B8', defaults: { name: { value: "" }, serialport: { value: "/dev/ttyAMA2", required: true }, serialbaud: { value: "9600", required: true, validate: RED.validators.number() }, databits: { value: 8, required: true }, parity: { value: "none", required: true }, stopbits: { value: 1, required: true }, waitfor: {value: ""}, newline: {value: "\\n"}, bin: {value: "false"}, out: {value: "char"}, addchar: {value: ""}, responsetimeout: {value: 10000}, rf_frequency: { value: "472.0625", required: true}, rf_factor: { value: 1024, required: true }, rf_mode: { value: "Normal", required: true }, rf_bw: { value: "125k", required: true }, rf_netid: { value: 0, required: true }, rf_power: { value: "7", required: true }, mode: { value: "Write", required: true }, }, inputs: 1, outputs: 1, icon: "smithtek.png", paletteLabel: "Loraconfig", label: function () { return this.name || this.to || "loraconfig"; }, labelStyle: function () { return this.name ? "node_label_italic" : ""; }, oneditprepare: function () { var previous = null; var baudrateList = [ { value: "9600", label: "9600", hasValue: false }, ]; var serialbaudType = "custom"; for (var i in baudrateList) { if (this.serialbaud == baudrateList[i].value) { serialbaudType = this.serialbaud; } } $("#node-config-input-serialbaud").typedInput({ default: this.serialbaud, types: baudrateList }); $("#node-config-lookup-serial").click(function () { $("#node-config-lookup-serial").addClass('disabled'); $.getJSON('serialports', function (data) { $("#node-config-lookup-serial").removeClass('disabled'); var ports = data || []; $("#node-input-serialport").autocomplete({ source: ports, minLength: 0, close: function (event, ui) { $("#node-input-serialport").autocomplete("destroy"); } }).autocomplete("search", ""); }); }); }, oneditsave: function () { var mytype = $("#node-config-input-serialbaud").typedInput('type'); if (mytype !== "other") { $("#node-config-input-serialbaud").typedInput('value', mytype); } this.serialbaud = $("#node-config-input-serialbaud").typedInput('value'); }, }); </script> <script type="text/html" data-template-name="loraconfig"> <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" placeholder="Node name"> </div> <div class="form-row" style="margin-top:12px; margin-bottom:0;"> <label style="width:66%;"><i class="fa fa-wrench"></i><b> CONFIG SERIAL</b></label> </div> <div class="form-row"> <label><i class="fa fa-random"></i> Serial Port</label> <input type="text" id="node-input-serialport" style="width:66%;" placeholder="Serialport" value="/dev/ttyAMA2" disabled> </div> ... <tr> <td>&nbsp;</td> <td> <input type="text" id="node-config-input-serialbaud" style="width:92%; height:28px;"> </td> <td> <!-- Commented out databits <select type="text" id="node-input-databits" style="width:90%; height:28px;"> <option value="8">8</option> </select> --> </td> <td> <!-- Commented out parity <select type="text" id="node-input-parity" style="width:90%; height:28px;"> <option value="none">none</option> </select> --> </td> <td> <!-- Commented out stopbits <select type="text" id="node-input-stopbits" style="width:60px; height:28px;"> <option value="1">1 (4 dBm)</option> </select> --> </td> </tr> ... </table> <div class="form-row" style="margin-top:12px; margin-bottom:0;"> <label><i class="fa fa-sign-in"></i> <span >Input</span></label> </div> <div class="form-row" style="padding-left:18px; margin-bottom:4px;"> <span>Optionally wait for a start character of</span> <input type="text" id="node-input-waitfor" style="width:50px; height:28px;"> <span>, then</span> </div> <div class="form-row" style="padding-left:18px; margin-bottom:4px;"> <span>Split input </span> <select type="text" id="node-input-out" style="margin-left:11px; width:200px; height:28px;"> <option value="char" >on the character</option> <option value="time" >after a timeout of</option> <option value="interbyte" >after a silence of</option> <option value="count" >into fixed lengths of</option> </select> <input type="text" id="node-input-newline" style="width:50px; height:28px;"> <span id="node-units"></span> </div> <div class="form-row" style="padding-left:18px; margin-bottom:4px;"> <span>and deliver</span> <select type="text" id="node-input-bin" style="margin-left:5px; width:150px; height:28px;"> <option value="false">ascii</option> <option value="bin">binary</option> </select> </div> <div class="form-row" style="margin-top:16px; margin-bottom:0;"> <label><i class="fa fa-sign-out"></i> <span>output</span></label> </div> <div class="form-row" style="padding-left:18px; margin-bottom:4px;"> <label style="width:auto;" for="node-input-addchar"><span>Add character to output messages</span></label> <input type="text" id="node-input-addchar" style="width:50px; height:28px;"> </div> <div class="form-row" style="margin-top:16px; margin-bottom:0;"> <label><i class="fa fa-exchange"></i> <span>request</span></label> </div> <div class="form-row" style="padding-left:18px; margin-bottom:18px;"> <span>Default response timeout:</span> <input type="text" id="node-input-responsetimeout" style="width:60px; height:28px;"> <span>ms</span> </div> </div> <div class="form-row" style="margin-top:12px; margin-bottom:0;"> <label style="width:66%;"><i class="fa fa-wrench"></i><b> CONFIG LORA</b></label> <div class="form-row" style="margin-top:12px; margin-bottom:12px;"> <label style="width:calc(40% - 1px)">frequency:</label> <input list="rf_frequencies" id="node-input-rf_frequency" style="width:calc(50% - 1px)"> <datalist id="rf_frequencies"> <option value="472.0625">AU</option> <option value="900">USA900</option> <option value="433">EU433</option> <option value="433">EU898</option> </datalist> </input> </div> <div class="form-row" style="margin-top:12px; margin-bottom:12px; "> <label style="width:calc(40% - 1px)">spreading factor:</label> <!-- <input type="text" id="node-input-rf_factor" placeholder="1024" style="width:calc(50% - 1px)"> --> <td><select type="text" id="node-input-rf_factor" style="width:calc(50% - 1px)"> <option value="128">128</option> <option value="256">256</option> <option value="512">512</option> <option value="1024">1024</option> <option value="2048">2048</option> <option value="4096">4096</option> </select></td> </div> <div class="form-row" style="margin-top:12px; margin-bottom:12px; "> <label style="width:calc(40% - 1px)">bw (k):</label> <!-- <input type="text" id="node-input-rf_bw" placeholder="125K" style="width:calc(50% - 1px)"> --> <td><select type="text" id="node-input-rf_bw" style="width:calc(50% - 1px)"> <option value="62.5k">62.5k</option> <option value="125k">125k</option> <option value="250k">250k</option> <option value="500k">500k</option> <!-- <option value="5">5 (14 dBm)</option> <option value="6">6 (17 dBm)</option> <option value="7">7 (20 dBm)</option> --> </select></td> </div> <div class="form-row" style="margin-top:12px; margin-bottom:12px; "> <label style="width:calc(40% - 1px)">Net ID:</label> <input type="text" id="node-input-rf_netid" placeholder="0" style="width:calc(50% - 1px)"> </div> <div class="form-row" style="margin-top:12px; margin-bottom:12px; "> <label style="width:calc(40% - 1px)">Power:</label> <!-- <input type="text" id="node-input-rf_power" placeholder="7" style="width:calc(50% - 1px)"> --> <td><select type="text" id="node-input-rf_power" style="width:calc(50% - 1px)"> <option value="1">1 (4 dBm)</option> <option value="2">2 (7 dBm)</option> <option value="3">3 (10 dBm)</option> <option value="4">4 (13 dBm)</option> <option value="5">5 (14 dBm)</option> <option value="6">6 (17 dBm)</option> <option value="7">7 (20 dBm)</option> </select></td> </div> </div> <div class="form-row"> <div class="form-row" style="margin-top:12px; margin-bottom:0;"> <label><i class="fa fa-sign-in"></i><b> MODE : </b></label> <td><select type="text" id="node-input-mode" width="110px" style="width:110px; height:28px;"> <option value="Write">Write</option> <option value="Read">Read</option> <option value="Service">Service & AES Config</option> </select></td> </div> <!-- <input type="text" id="node-input-server" placeholder="server" style="width:calc(70% - 1px)"> --> </div> </script> <script type="text/markdown" data-help-name="loraconfig"> # Smithtek LoRa Module ## WARNING - Ensure you set the properties of this node to match the regulations of your region/country. ## COMMUNICATION SETUP - The default LoRa Port is: `/dev/ttyAMA2`. You do not need to change this! - Make sure no other nodes in your flow are using `/dev/ttyAMA2`. Check your configuration nodes first and disable any configurations using this serial channel. - If you don't, the node won't work, and you will be unable to write settings. The default serial nodes and Modbus nodes can often be a culprit. - Check all configs before starting! ## MODE There are 3 modes: `Read`, `Write`, `Service and AES mode`. - In `Read` or `Write` mode, a payload must be injected into the input of the node to make it work. - The result will be printed on the debug bar a few seconds later. ### `Read` - Read mode will read the current status of the LoRa module. The result will be displayed in the debug bar in JSON format. ### `Write` - Write mode will send the new settings you have created in the node properties. ### `Service & AES mode` - Service and AES mode has two functions: 1. It will act as a transparent serial interface. In this mode, you can send and receive data from other LoRa modules in your network. The serial interface can be tuned to detect when packets arrive and end. The input message property can recognize a special character or silence detection, to determine the end of a payload message. The output message property can add a special character. Messages can be delivered in ASCII or binary. 2. In this mode, you can use the additional `Smithtek-nodered-lora-aes` node. It will allow you to dynamically turn on/off the AES mode and change the 8-digit magic key. ## PROPERTIES - Default request timeout in ms. Set this property higher when you are transmitting messages over long distances or have larger messages to send. - `Frequency`: This is the radio band the module will communicate on. Warning: Please ensure the setting used is compatible with your country's rules and regulations. - `BW (k) kHz`: This is the bandwidth in kHz. - `Spreading Factor`: This is the air data rate in Kbps. - `NET ID`: This is the ID of your module. This allows you to have multiple communications networks in the same area. Only devices with the same Net ID will communicate with each other. The ID range is 0 - 255. - `Power`: This is the amount of power applied to the RF transmitter. The Settings are 1-7 (1=4dBm, 2=7dBm, 3=10dBm, 4=13dBm, 5=14dBm, 6=17dBm, 7=20dBm). ## Frequency Range - AU = 430 - 510Mhz - EU (CE) 863 - 875Mhz - USA (FCC) 902 - 928Mhz ## Programming When using this node, you must press the deploy after every action for the changes to take effect. For example, if you are selecting read mode and want to read the current settings, you must: 1. Drop the LoRa node to the flow area. 2. Drop and wire the Inject node to the LoRa Node in. 3. Drop and wire the debug node to the LoRa Node out. 4. Deploy the flow. 5. Hit inject; the current settings of the module will display in the debug window. ## CONTACT - Email: [info@smithtek.com.au](mailto:info@smithtek.com.au) - Visit: [www.smithtek.com.au](http://www.smithtek.com.au)