From 71f9d3ad989a5d18fdda7d5edf6f97fda38bf27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20L=C3=A9caud=C3=A9?= Date: Mon, 14 Mar 2016 16:24:22 -0400 Subject: [PATCH] node-red-node-physical-web: Added uid mode --- hardware/physical-web/physical-web.html | 29 +++++++++++++++++ hardware/physical-web/physical-web.js | 42 ++++++++++++++++++++----- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/hardware/physical-web/physical-web.html b/hardware/physical-web/physical-web.html index 38e185fa..fb89326f 100644 --- a/hardware/physical-web/physical-web.html +++ b/hardware/physical-web/physical-web.html @@ -78,12 +78,27 @@ diff --git a/hardware/physical-web/physical-web.js b/hardware/physical-web/physical-web.js index 576bb84e..be556d45 100644 --- a/hardware/physical-web/physical-web.js +++ b/hardware/physical-web/physical-web.js @@ -23,9 +23,12 @@ module.exports = function(RED) { function Beacon(n) { RED.nodes.createNode(this,n); var node = this; + node.mode = n.mode; node.power = n.power; node.period = n.period * 10; node.url = n.url; + node.namespace = n.namespace; + node.instance = n.instance; node.options = { txPowerLevel: node.power, @@ -33,7 +36,7 @@ module.exports = function(RED) { tlmCount: 2 }; - if (node.url) { + if (node.mode === "url" && node.url) { if (!eddyBeacon) { eddyBeacon = true; try { @@ -46,13 +49,38 @@ module.exports = function(RED) { 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) { - try { - eddystoneBeacon.advertiseUrl(msg.payload, node.options); - node.status({fill:"green",shape:"dot",text:node.url.toString()}); - } catch(e) { - node.status({fill:"red",shape:"circle",text:"URL too long"}); - node.error('error updating beacon URL', e); + if (node.mode === "url") { + try { + eddystoneBeacon.advertiseUrl(msg.payload, node.options); + node.status({fill:"green",shape:"dot",text:msg.payload}); + } catch(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); + } } });