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 00000000..863a3f88 Binary files /dev/null and b/hardware/physical-web/icons/physical-web.png differ diff --git a/hardware/physical-web/package.json b/hardware/physical-web/package.json new file mode 100644 index 00000000..c0150a18 --- /dev/null +++ b/hardware/physical-web/package.json @@ -0,0 +1,33 @@ +{ + "name": "node-red-node-physical-web", + "version": "0.0.2", + "description": "A set of nodes to interact with the Phyical Web", + "main": "physical-web.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "node-red", + "physical-web", + "eddystone", + "beacon", + "ble" + ], + "node-red": { + "physical-web": "physical-web.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/node-red/node-red-nodes.git" + }, + "author": { + "name": "Ben Hardill", + "email": "hardillb@gmail.com", + "url": "http://www.hardill.me.uk/wordpress" + }, + "license": "APACHE-2.0", + "dependencies": { + "eddystone-beacon": "~1.0.4", + "eddystone-beacon-scanner": "~3.0.0" + } +} diff --git a/hardware/physical-web/physical-web.html b/hardware/physical-web/physical-web.html new file mode 100644 index 00000000..66aabf89 --- /dev/null +++ b/hardware/physical-web/physical-web.html @@ -0,0 +1,143 @@ + + + + + + + + + + + + \ 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