How to use blueIOT with „node-RED“

„node-RED“ is a visual tool for modeling the Internet of Things (IOT). You can find it here (link). We do use node-RED to interact with the Internet based on the sensor data received from the blueIOT. In this example we do use blueIOT as an mobile beacon for proximity detection to an home gateway: we can switch a wireless power socket or the piFace! The limit is just your imagination …

nodered

Step1: modify your 101-scanBLE.js like this (attention the UUID is equal to the MAC and lower case), this is
your easy start …

//might need to modify accordingly
var RED = require(process.env.NODE_RED_HOME + „/red/red“);

//import noble
var noble = require(’noble‘);

// The main node definition – most things happen in here
function BleScan(n) {
// Create a RED node
RED.nodes.createNode(this, n);

var msg = {};
var node = this;

//get uuid from user
this.ble_uuid = n.ble_uuid;

this.on(„input“, function (msg) {
noble.startScanning();
});

noble.on(’scanStart‘, function (msg) {
var msg = {};
msg.topic = node.topic;
console.log(’scanning initiated…‘);
});

noble.on(‚discover‘, function (peripheral) {

var msg = {};
msg.topic = node.topic;
//check for the device name and the UUID (first one from the UUID list)
console.log(peripheral.uuid);
console.log(peripheral.rssi);
if (peripheral.uuid == node.ble_uuid) {
msg.payload = peripheral.rssi;
node.send(msg);
noble.stopScanning();
}
});

this.on(„close“, function () {
try {
noble.stopScanning();
}
catch (err) {
console.log(err);
}
});
}

// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType(„scanBLE“, BleScan);

Step2: cut & caste the code for node-Red:

[{„id“:“777998f9.888668″,“type“:“scanBLE“,“name“:““,“ble_name“:“Sensor Tag“,“ble_uuid“:“000780789c4a“,“x“:267.888916015625,“y“:128.11114501953125,“z“:“2d4d99e7.d2b266″,“wires“:[[„9caaef8.f63551″,“14791f11.5caac1“]]},{„id“:“9caaef8.f63551″,“type“:“debug“,“name“:““,“active“:false,“complete“:“true“,“x“:429.00006103515625,“y“:293.4444580078125,“z“:“2d4d99e7.d2b266″,“wires“:[]},{„id“:“d7a291a6.285d7″,“type“:“rpi-piface out“,“name“:““,“pin“:“LED 0 / Relay 0″,“x“:656.6666870117188,“y“:110.33334350585938,“z“:“2d4d99e7.d2b266″,“wires“:[]},{„id“:“307d4360.cf82bc“,“type“:“inject“,“name“:“Reset“,“topic“:““,“payload“:“0″,“payloadType“:“string“,“repeat“:““,“crontab“:““,“once“:false,“x“:409.2222595214844,“y“:71.88887023925781,“z“:“2d4d99e7.d2b266″,“wires“:[[„d7a291a6.285d7“]]},{„id“:“da886702.257798″,“type“:“inject“,“name“:“Start Discovery“,“topic“:““,“payload“:““,“payloadType“:“date“,“repeat“:“1″,“crontab“:““,“once“:false,“x“:136.0000114440918,“y“:70.22222900390625,“z“:“2d4d99e7.d2b266″,“wires“:[[„777998f9.888668“]]},{„id“:“14791f11.5caac1″,“type“:“function“,“name“:““,“func“:“if (msg.payload > -40)\n{\nmsg.payload = \“1\“;\n}\nelse\nmsg.payload = \“0\“;\nreturn msg;“,“outputs“:1,“x“:457,“y“:173,“z“:“2d4d99e7.d2b266″,“wires“:[[„34d54efb.bcae4a“,“d7a291a6.285d7″]]},{„id“:“34d54efb.bcae4a“,“type“:“debug“,“name“:““,“active“:true,“complete“:“true“,“x“:635,“y“:234,“z“:“2d4d99e7.d2b266″,“wires“:[]}]