From d9fb187cddf0e4982064ca6761c5955104da4445 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 23 Nov 2015 15:24:26 +0000 Subject: [PATCH] Pushing Physical-web node to node-red-nodes Hopefully fixing jslint errors And once more Getting closer I think I've finally squashed all the jshint errors --- hardware/physical-web/.gitignore | 1 + hardware/physical-web/README.md | 53 +++++++ hardware/physical-web/icons/physical-web.png | Bin 0 -> 829 bytes hardware/physical-web/package.json | 33 +++++ hardware/physical-web/physical-web.html | 143 +++++++++++++++++++ hardware/physical-web/physical-web.js | 87 +++++++++++ 6 files changed, 317 insertions(+) create mode 100644 hardware/physical-web/.gitignore create mode 100644 hardware/physical-web/README.md create mode 100644 hardware/physical-web/icons/physical-web.png create mode 100644 hardware/physical-web/package.json create mode 100644 hardware/physical-web/physical-web.html create mode 100644 hardware/physical-web/physical-web.js diff --git a/hardware/physical-web/.gitignore b/hardware/physical-web/.gitignore new file mode 100644 index 00000000..8d87b1d2 --- /dev/null +++ b/hardware/physical-web/.gitignore @@ -0,0 +1 @@ +node_modules/* diff --git a/hardware/physical-web/README.md b/hardware/physical-web/README.md new file mode 100644 index 00000000..181acc44 --- /dev/null +++ b/hardware/physical-web/README.md @@ -0,0 +1,53 @@ +# node-red-node-physical-web + +install with + +npm install node-red-node-physical-web + +Then on Linux follow these instrucations: + +https://github.com/sandeepmistry/bleno#running-on-linux + + +## Physical-Web out + +A node to allow Node-RED to act as an Eddystone beacon broadcasting URLs + +### Config + +The config window lets you set the inital URL, anouncement power and period for the Eddystone. + +Any messages received will update the advertised URL from the msg.payload + +## Physical-Web in + +A node to scan for local Eddystones and output information about discovered URLs and TLM data. + +Two types of messages will be emitted: + +- **URL** - + - *type* - Eddystone type + - *txPower* - Received power at 0m in dBm + - *url* - The URL the beacon is broadcasting + - *tlm* - TLM data, if the device is interleaving broadcasts + - *rssi* - RSSI of the beacon + - *distance* - Estimated distance to the beacon +- **UID** - + - *type* - Eddystone type + - *txPower* - Received power at 0m in dBm + - *namespace* - 10-byte ID of namspace + - *instance* - 6-byte ID insance + - *tlm* - TLM data, if the device is interleaving broadcasts + - *rssi* - RSSI of the beacon + - *distance* - Estimated distance to the beacon + +Where the tlm data will be in the following format + +- **tlm** - + - *version* - TML version + - *vbatt* - Battery Voltage + - *temp* - Temperature + - *advCnt* - Advertising PDU count + - *secCnt* - Time since power on or reboot + - *rssi* - RSSI of the beacon + - *distance* - Estimated distance to the beacon diff --git a/hardware/physical-web/icons/physical-web.png b/hardware/physical-web/icons/physical-web.png new file mode 100644 index 0000000000000000000000000000000000000000..863a3f88acc7b233b1a338505a948949559f5da6 GIT binary patch literal 829 zcmeAS@N?(olHy`uVBq!ia0vp^B0wy`!2%=$oJ9WuDVB6cUq=Rpjs4tz5?O(Kg=CK) zUj~LMH3o);76yi2K%s^g3=E|P3=FRl7#OT(FffQ0%-I!a1C(G&@^*J&_}|`tWO>_43rfDVaD|Nmw@&$$$7dshG?8Gy&T(pB~|9w$JhVkbJNOlr*2C#*XrC_de-WN z=ncpB3m3dOY1P41&7drLn@2O~l=uTjZ#kE;AVoQri)qnfERpPjB0nbxdQM@zb>>a| z^UDW)4!;SyUi;(sz3XS+@7gh0rL$wUP3l4U2b213lNXTZU`^esP z7I~+3>^=7~EBocIliX$*RpFWcJ~L~M zxAN>wk6xZf_<$BLA`=pxPKUyctuPuA=;~J+P z3BlI6x1ROhSoe79j=PfcvuABfn15-7CHtD-ihG{hXKZ+}$NEzLuToxLUS9p|=ufi@ zOMOe(L!XHV3g0U~8N29VgV_s<6rVdU%hh9+%fIPyUmN^+(zN=kA6K;*TA%sW{h~bj zhHcB&3x7}DGtr#9=(^LylUKryY&M(h{CQ#8dc*bBA6{2^7hjz(xj^`y%!2&cfB176 z;$E-N>-(#3=CFLuhlSGN$^RKl9zHMLw04CpF!`vKxJHzuB$lLFB^RXvDF!10LsMNt zLtP_-5F-OCV*@Kg6Kw+nD+2>@1=jB<8glbfGSe#2G#Hs!nV3N|6sF(Z1Joc1vLQG> qt)x7$D3!r6B|j-u!8128JvAsbF{QHbWGX04GkCiCxvX + + + + + + + + + + + \ No newline at end of file diff --git a/hardware/physical-web/physical-web.js b/hardware/physical-web/physical-web.js new file mode 100644 index 00000000..e3a20b88 --- /dev/null +++ b/hardware/physical-web/physical-web.js @@ -0,0 +1,87 @@ +/** + * Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + "use strict"; + + var eddystoneBeacon = require('eddystone-beacon'); + var EddystoneBeaconScanner = require('eddystone-beacon-scanner'); + + function Beacon(n){ + RED.nodes.createNode(this,n); + var node = this; + node.power = n.power; + node.period = n.period; + node.url = n.url; + + node.options = { + txPowerLevel: node.power, + tlmPeriod: node.period + } + + + if (node.url) { + try { + eddystoneBeacon.advertiseUrl(msg.payload, node.options); + } catch(e){ + node.error('Error setting beacon URL', e); + } + } + + node.on('input', function(msg){ + try { + eddystoneBeacon.advertiseUrl(msg.payload, node.options); + } catch(e){ + node.error('error updating beacon URL', e); + } + }); + + node.on('close', function(done){ + try { + eddystoneBeacon.stop(); + done(); + } catch(e){ + node.error('error shuttingdown beacon', e); + } + }); + + } + RED.nodes.registerType("PhysicalWeb out", Beacon); + + function Scanner(n){ + RED.nodes.createNode(this,n); + var node = this; + node.topic = n.topic; + + function onFound(beacon) { + node.send({ + topic: node.topic, + payload: beacon + }); + } + + EddystoneBeaconScanner.on('found', onFound); + EddystoneBeaconScanner.on('updated', onFound); + + node.on('close',function(done){ + EddystoneBeaconScanner.removeListener('found', onFound); + EddystoneBeaconScanner.removeListener('updated', onFound); + done(); + }); + } + RED.nodes.registerType("PhysicalWeb in", Scanner); + +}; \ No newline at end of file