Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vesta
rigado-devkit
Commits
da0bb96e
Commit
da0bb96e
authored
Dec 12, 2017
by
Spencer Williams
Browse files
Merge branch 'master' into configurable-uuids
parents
36f7b548
76877814
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
examples/dev-kit.json
View file @
da0bb96e
This diff is collapsed.
Click to expand it.
noble-connect/node-red-noble-connect.html
View file @
da0bb96e
<!-- 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-
device
_name
"
><
i
class
=
"
fa fa-tasks
"
><
/i>
Device Name
</
label
>
<
input
type
=
"
text
"
id
=
"
node-input-
device_name
"
>
<
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-adv_service_uuid
"
><
i
class
=
"
fa fa-tasks
"
><
/i>Advertisement Service UUID</
label
>
<
input
type
=
"
text
"
id
=
"
node-input-adv_service_uuid
"
>
...
...
@@ -42,11 +50,13 @@
category
:
"
Rigado DevKit
"
,
color
:
"
#A6BBCF
"
,
defaults
:
{
device_name
:
{
value
:
""
},
adv_service_uuid
:
{
value
:
""
},
tms_service_uuid
:
{
value
:
""
},
tms_raw_rx_char_uuid
:
{
value
:
""
},
tms_raw_rx_char_length
:
{
value
:
""
},
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
,
...
...
noble-connect/node-red-noble-connect.js
View file @
da0bb96e
...
...
@@ -2,6 +2,8 @@
const
MAX_PERIPHERALS
=
8
;
const
DEFAULT_DEVICE_NAME
=
"
Thingy
"
;
module
.
exports
=
function
(
RED
)
{
var
async
=
require
(
"
async
"
);
var
noble
=
require
(
"
noble
"
);
...
...
@@ -14,12 +16,21 @@ module.exports = function(RED) {
node
.
log
(
"
Created node
"
+
node
.
id
);
node
.
device_name
=
config
.
device_name
;
node
.
adv_service_uuid
=
config
.
adv_service_uuid
;
node
.
tms_service_uuid
=
config
.
tms_service_uuid
;
node
.
tms_raw_rx_char_uuid
=
config
.
tms_ras_rx_char_uuid
;
node
.
tms_raw_rx_char_length
=
config
.
tms_raw_rx_char_length
;
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
;
...
...
@@ -81,7 +92,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
;
}
...
...
@@ -89,9 +100,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
]);
}
...
...
@@ -149,11 +160,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
"
)
{
...
...
@@ -182,7 +193,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
"
);
node
.
log
(
"
Scanning for BLEs started
. UUIDs:
"
+
node
.
uuids
+
"
Name:
"
+
node
.
target_name
);
node
.
status
({
fill
:
"
green
"
,
shape
:
"
dot
"
,
text
:
"
scanning
"
});
node
.
scanning
=
true
;
}
...
...
@@ -224,6 +235,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
)
{
...
...
@@ -232,7 +244,7 @@ module.exports = function(RED) {
}
//find the svc
if
(
uuids
&&
uuids
.
indexOf
(
node
.
adv_service_uuid
)
>=
0
&&
adv
.
localName
==
=
node
.
device_name
)
{
if
(
uuids
&&
uuids
.
indexOf
(
node
.
adv_service_uuid
)
>=
0
&&
adv
.
localName
==
node
.
target_name
&&
rssi
>=
node
.
target_rssi
)
{
if
(
semaphore
.
available
())
{
semaphore
.
take
(()
=>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment