mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Merge pull request #188 from natcl/master
Added uid mode to node-red-node-physical
This commit is contained in:
commit
3314a80482
@ -78,16 +78,35 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-template-name="PhysicalWeb out">
|
<script type="text/x-red" data-template-name="PhysicalWeb out">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
<label for="node-input-mode"><i class="fa fa-wrench"></i> <span>Mode</span></label>
|
||||||
|
<select id="node-input-mode" style='width:100px'>
|
||||||
|
<option value="url">url</option>
|
||||||
|
<option value="uid">uid</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row" id="node-url">
|
||||||
<label for="node-input-url"><i class="fa fa-link"></i> URL</label>
|
<label for="node-input-url"><i class="fa fa-link"></i> URL</label>
|
||||||
<input type="text" id="node-input-url" style="width:250px;" placeholder="http://...">
|
<input type="text" id="node-input-url" style="width:250px;" placeholder="http://...">
|
||||||
<!--<button type="button" id="node-input-url-shorten" disabled=true>Shorten</button> -->
|
<!--<button type="button" id="node-input-url-shorten" disabled=true>Shorten</button> -->
|
||||||
<p style="margin-left:100px; width:70%">This URL needs to be shorter than 18 bytes
|
<p style="margin-left:100px; width:70%">This URL needs to be shorter than 18 bytes
|
||||||
in length to meet Eddystone spec</p>
|
in length to meet Eddystone spec</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row" id="node-namespace">
|
||||||
|
<label for="node-input-namespace"><i class="fa fa-bluetooth"></i> Namespace</label>
|
||||||
|
<input type="text" id="node-input-namespace" style="width:250px;">
|
||||||
|
</div>
|
||||||
|
<div class="form-row" id="node-instance">
|
||||||
|
<label for="node-input-instance"><i class="fa fa-bluetooth"></i> Instance</label>
|
||||||
|
<input type="text" id="node-input-instance" style="width:250px;">
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-period"><i class="fa fa-repeat"></i> Period (S)</label>
|
<label for="node-input-period"><i class="fa fa-repeat"></i> Period</label>
|
||||||
<input type="text" id="node-input-period" style="width:80px;" placeholder="Period">
|
<input type="text" id="node-input-period" style="width:80px;" placeholder="Period">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-count"><i class="fa fa-repeat"></i> Count</label>
|
||||||
|
<input type="text" id="node-input-count" style="width:80px;" placeholder="Count">
|
||||||
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-power"><i class="fa fa-battery-half"></i> Power (dB)</label>
|
<label for="node-input-power"><i class="fa fa-battery-half"></i> Power (dB)</label>
|
||||||
<input type="text" id="node-input-power" style="width:80px;" placeholder="Power">
|
<input type="text" id="node-input-power" style="width:80px;" placeholder="Power">
|
||||||
@ -101,11 +120,20 @@
|
|||||||
|
|
||||||
<script type="text/x-red" data-help-name="PhysicalWeb out">
|
<script type="text/x-red" data-help-name="PhysicalWeb out">
|
||||||
<p><a href="https://google.github.io/physical-web/">Physical Web</a> beacon node.</p>
|
<p><a href="https://google.github.io/physical-web/">Physical Web</a> beacon node.</p>
|
||||||
<p>This node can take the value of <code>msg.payload</code> and publishes it as an Eddystone URL
|
<p>This node can be set to URL mode or UID mode</p>
|
||||||
|
<p>In <strong>URL mode</strong> this node can take the value of <code>msg.payload</code> and publishes it as an Eddystone URL
|
||||||
announcement. URLs <b>must</b> be less than 18 bytes long, so should be run through a shortner first.</p>
|
announcement. URLs <b>must</b> be less than 18 bytes long, so should be run through a shortner first.</p>
|
||||||
<p>You can also preset the URL, in which case the node does not require any input.</p>
|
<p>You can also preset the URL, in which case the node does not require any input.</p>
|
||||||
<p>The config window will allow you to set the powerlevel (-30 to 100 db) and the period (S)
|
<p>In <strong>UID mode</strong> this node can take the 10 bytes namespace (as an HEX string) as <code>msg.payload</code>
|
||||||
between anouncements.</p>
|
and the 6 bytes instance (as an HEX string) as <code>msg.topic</code>.
|
||||||
|
<p>The config window will allow you to set the powerlevel (-30 to 100 db) and the TLM count and period values.</p>
|
||||||
|
<p>TLM stands for telemetry data and is a type of packet sent alongside the main packet that provides diagnostics information.
|
||||||
|
The count and period determine the ratio of TLM packets sent versus normal packets.
|
||||||
|
A period of 10 and a count of 2 means that 2 TLM packets are sent for each 10 advertisements.</p>
|
||||||
|
|
||||||
|
<p>The actual advertisement rate can be set by changing the <code>BLENO_ADVERTISING_INTERVAL</code> environment variable.
|
||||||
|
For example, to set a 20ms interval, you would need to type <code>sudo BLENO_ADVERTISING_INTERVAL=20 node-red</code></p>
|
||||||
|
|
||||||
<p>Linux users should <a href="https://github.com/sandeepmistry/bleno#running-on-linux" target="_new">READ THIS</a>.</p>
|
<p>Linux users should <a href="https://github.com/sandeepmistry/bleno#running-on-linux" target="_new">READ THIS</a>.</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -114,9 +142,13 @@
|
|||||||
category: 'output',
|
category: 'output',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
|
mode: {value:"url"},
|
||||||
url: {value:"",validate:function(v) {return v.length<19; }},
|
url: {value:"",validate:function(v) {return v.length<19; }},
|
||||||
|
namespace: {value:""},
|
||||||
|
instance: {value:""},
|
||||||
power: {value:"-21",validate:RED.validators.number()},
|
power: {value:"-21",validate:RED.validators.number()},
|
||||||
period: {value:"1",validate:RED.validators.number()}
|
period: {value:"10",validate:RED.validators.number()},
|
||||||
|
count: {value:"2",validate:RED.validators.number()}
|
||||||
},
|
},
|
||||||
color: "#2F7ACD",
|
color: "#2F7ACD",
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -129,8 +161,20 @@
|
|||||||
return this.name?"node_label_italic":"";
|
return this.name?"node_label_italic":"";
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
$( "#node-input-period" ).spinner({min:1});
|
$( "#node-input-period" ).spinner({min:0});
|
||||||
|
$( "#node-input-count" ).spinner({min:0});
|
||||||
$( "#node-input-power" ).spinner({min:-30,max:100});
|
$( "#node-input-power" ).spinner({min:-30,max:100});
|
||||||
|
$("#node-input-mode").on("change",function() {
|
||||||
|
if ($("#node-input-mode").val() === "uid") {
|
||||||
|
$("#node-url").hide();
|
||||||
|
$("#node-namespace").show();
|
||||||
|
$("#node-instance").show();
|
||||||
|
} else {
|
||||||
|
$("#node-url").show();
|
||||||
|
$("#node-namespace").hide();
|
||||||
|
$("#node-instance").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -23,17 +23,21 @@ module.exports = function(RED) {
|
|||||||
function Beacon(n) {
|
function Beacon(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
var node = this;
|
var node = this;
|
||||||
|
node.mode = n.mode;
|
||||||
node.power = n.power;
|
node.power = n.power;
|
||||||
node.period = n.period * 10;
|
node.period = n.period;
|
||||||
|
node.count = n.count;
|
||||||
node.url = n.url;
|
node.url = n.url;
|
||||||
|
node.namespace = n.namespace;
|
||||||
|
node.instance = n.instance;
|
||||||
|
|
||||||
node.options = {
|
node.options = {
|
||||||
txPowerLevel: node.power,
|
txPowerLevel: node.power,
|
||||||
tlmPeriod: node.period,
|
tlmPeriod: node.period,
|
||||||
tlmCount: 2
|
tlmCount: node.count
|
||||||
};
|
};
|
||||||
|
|
||||||
if (node.url) {
|
if (node.mode === "url" && node.url) {
|
||||||
if (!eddyBeacon) {
|
if (!eddyBeacon) {
|
||||||
eddyBeacon = true;
|
eddyBeacon = true;
|
||||||
try {
|
try {
|
||||||
@ -46,13 +50,38 @@ module.exports = function(RED) {
|
|||||||
else {node.warn('Beacon already in use');}
|
else {node.warn('Beacon already in use');}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.mode === "uid") {
|
||||||
|
if (!eddyBeacon) {
|
||||||
|
eddyBeacon = true;
|
||||||
|
try {
|
||||||
|
eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
|
||||||
|
node.status({fill:"green",shape:"dot",text:node.namespace});
|
||||||
|
} catch(e) {
|
||||||
|
node.error('Error setting beacon information', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {node.warn('Beacon already in use');}
|
||||||
|
}
|
||||||
|
|
||||||
node.on('input', function(msg) {
|
node.on('input', function(msg) {
|
||||||
try {
|
if (node.mode === "url") {
|
||||||
eddystoneBeacon.advertiseUrl(msg.payload, node.options);
|
try {
|
||||||
node.status({fill:"green",shape:"dot",text:node.url.toString()});
|
eddystoneBeacon.advertiseUrl(msg.payload, node.options);
|
||||||
} catch(e) {
|
node.status({fill:"green",shape:"dot",text:msg.payload});
|
||||||
node.status({fill:"red",shape:"circle",text:"URL too long"});
|
} catch(e) {
|
||||||
node.error('error updating beacon URL', e);
|
node.status({fill:"red",shape:"dot",text:"URL too long"});
|
||||||
|
node.error('error updating beacon URL', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// uid mode
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
eddystoneBeacon.advertiseUid(msg.payload, msg.topic, node.options);
|
||||||
|
node.status({fill:"green",shape:"dot",text:msg.payload});
|
||||||
|
} catch(e) {
|
||||||
|
node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
|
||||||
|
node.error('Error setting beacon information', e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user