Commit 591f2aba authored by David Mondou's avatar David Mondou
Browse files

Merge branch 'feature/connect_upgrades' into 'master'

Feature/connect upgrades

See merge request !11
parents 5de22abc da4f249a
This diff is collapsed.
<!-- edit dialog -->
<script type="text/x-red" data-template-name="noble-connect">
<!-- Limit to particular device name (default to Thingy). Note that there is space for a max of 8 characters for the name in the Thingy advertising packet -->
<div class="form-row">
<label for="node-input-target_name"><i class="fa fa-tasks"></i> Restrict by Name (8 char max)</label>
<input type="text" id="node-input-target_name" placeholder="Thingy">
</div>
<div class="form-tips">Leave empty for scanning all devices with default name of Thingy.</div>
<!-- Limit to stronger RSSI devices -->
<div class="form-row">
<label for="node-input-rssi"><i class="fa fa-tasks"></i> Restrict by RSSI</label>
<input type="text" id="node-input-rssi" placeholder="-100..0">
</div>
<div class="form-tips">Leave empty for scanning all devices regardless of signal strength.</div>
<!-- Limit to list of UUIDs -->
<div class="form-row">
<label for="node-input-uuids"><i class="fa fa-tasks"></i> Restrict by Service UUID</label>
......@@ -24,6 +36,8 @@
color: "#A6BBCF",
defaults: {
uuids: {value: "", validate: RED.validators.regex(/^([a-fA-F0-9]{32}){0,1}(?:,[a-fA-F0-9]{32})*$/)},
target_name: {value: "", validate: function(v) {return v.length >= 0 && v.length <= 8} },
rssi: {value: "-100", validate: function(v) {return v>= -100 && v <= 0} },
name: {value: ""}
},
inputs:1,
......
......@@ -2,7 +2,7 @@
const MAX_PERIPHERALS = 8;
const DEVICE_NAME = "Thingy";
const DEFAULT_DEVICE_NAME = "Thingy";
const THINGY_ADV_SERVICE_UUID = "ef6801009b3549339b1052ffa9740042";
const TMS_SERVICE_UUID = "ef6804009b3549339b1052ffa9740042";
const TMS_RAW_RX_CHAR_UUID = "ef6804069b3549339b1052ffa9740042";
......@@ -26,6 +26,16 @@ module.exports = function(RED) {
node.uuids = config.uuids.split(",");
}
node.target_name = DEFAULT_DEVICE_NAME;
if (typeof config.target_name !== "undefined" && config.target_name !== "") {
node.target_name = config.target_name;
}
node.target_rssi = -100;
if (typeof config.rssi !== "undefined" && config.rssi !== "") {
node.target_rssi = config.rssi;
}
// initialize node state on first deploy
node.scanning = false;
node.connection_count = 0;
......@@ -87,7 +97,7 @@ module.exports = function(RED) {
if (p.hasOwnProperty("advertisement") && p.advertisement.hasOwnProperty("localName")) {
node.peripherals[p.uuid].name = p.advertisement.localName;
}
if (p.hasOwnProperty("connected")) {
node.peripherals[p.uuid].connected = p.connected;
}
......@@ -95,9 +105,9 @@ module.exports = function(RED) {
function disconnectAll() {
node.log("disconnect all");
var uuids = [];
for (var i=0; i<Object.keys(node.peripherals).length; i++) {
uuids.push(Object.keys(node.peripherals)[i]);
}
......@@ -155,11 +165,11 @@ module.exports = function(RED) {
node.log(mac+": enable notifications...");
rx.notify(true, (callback) => {
node.log(mac+": notifications enabled");
async.whilst(
//run while connected
() => { return true; },
//loop body (wait for notifications)
(cb) => {
if (peripheral.state !== "connected") {
......@@ -188,7 +198,7 @@ module.exports = function(RED) {
node.warn("NoBLE scanning error: "+nobleError);
node.status({fill: "red", shape: "dot", text: "error"});
} else {
node.log("Scanning for BLEs started. UUIDs: " + node.uuids);
node.log("Scanning for BLEs started. UUIDs: " + node.uuids + " Name: " + node.target_name);
node.status({fill:"green",shape:"dot",text:"scanning"});
node.scanning = true;
}
......@@ -230,6 +240,7 @@ module.exports = function(RED) {
noble.on("discover", (peripheral) => {
var adv = peripheral.advertisement;
var uuids = adv.serviceUuids;
var rssi = peripheral.rssi;
//stop and bail out
if (node.connection_count >= MAX_PERIPHERALS) {
......@@ -238,7 +249,7 @@ module.exports = function(RED) {
}
//find the svc
if (uuids && uuids.indexOf(THINGY_ADV_SERVICE_UUID) >= 0 && adv.localName === DEVICE_NAME) {
if (uuids && uuids.indexOf(THINGY_ADV_SERVICE_UUID) >= 0 && adv.localName == node.target_name && rssi >= node.target_rssi) {
if (semaphore.available()) {
semaphore.take(() => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment