Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vesta Example
nodejs-sensor-cloud
Commits
cba91305
Commit
cba91305
authored
Jul 12, 2017
by
Spencer Williams
Browse files
comments
parent
78b48524
Changes
3
Hide whitespace changes
Inline
Side-by-side
device.js
View file @
cba91305
'
use strict
'
;
/**
* A Device object manages an edge device and its bluetooth communication
*/
class
Device
{
constructor
(
bleDevice
)
{
this
.
id
=
bleDevice
.
address
.
replace
(
/:/g
,
''
);
...
...
@@ -7,6 +10,10 @@ class Device {
this
.
fwVersion
=
null
;
}
/**
* Returns a Promise that will resolve with the ble device's firmware revision,
* or reject with an error
*/
readFirmware
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
console
.
log
(
`
${
this
.
id
}
: readFirmwareRevision`
);
...
...
@@ -24,6 +31,10 @@ class Device {
});
}
/**
* Returns a Promise that will connect and set up the ble device with noble.
* Once set up, it will read the device's firmware and enable its luxometer.
*/
setUp
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
bleDevice
.
connectAndSetUp
((
setupError
)
=>
{
...
...
@@ -44,6 +55,9 @@ class Device {
});
}
/**
* Returns a Promise that will enable the device's luxometer
*/
enableLuxometer
()
{
return
new
Promise
((
resolve
)
=>
{
console
.
log
(
`
${
this
.
id
}
: enableLuxometer`
);
...
...
@@ -51,6 +65,9 @@ class Device {
});
}
/**
* Returns a Promise that will notify the device's luxometer
*/
notifyLuxometer
()
{
return
new
Promise
((
resolve
)
=>
{
console
.
log
(
`
${
this
.
id
}
: notifyLuxometer`
);
...
...
@@ -58,10 +75,14 @@ class Device {
});
}
onLuxometerChange
(
sendTelemetry
)
{
/**
* This function will bind its given callback to run when the ble device
* triggers a 'luxometerChange' event.
*/
onLuxometerChange
(
callback
)
{
console
.
log
(
`
${
this
.
id
}
: set up onluxchange`
);
this
.
bleDevice
.
on
(
'
luxometerChange
'
,
(
lux
)
=>
{
sendTelemetry
(
this
,
lux
);
callback
(
this
,
lux
);
});
return
this
.
notifyLuxometer
();
...
...
providers/aws.js
View file @
cba91305
...
...
@@ -6,7 +6,13 @@ const dateFormat = require('dateformat');
const
ProviderStrategy
=
require
(
'
./providerStrategy.js
'
);
/**
* A concrete Cloud Provider strategy for interacting with AWS Kinesis Firehose.
*/
class
AWSProvider
extends
ProviderStrategy
{
/**
* Initializes AWS config and a Firehose delivery stream
*/
constructor
(
config
)
{
super
(
config
);
this
.
name
=
'
AWS
'
;
...
...
@@ -26,6 +32,7 @@ class AWSProvider extends ProviderStrategy {
sendTelemetry
(
telemetry
)
{
const
now
=
new
Date
();
// AWS needs a specific time format
telemetry
.
timestamp
=
dateFormat
(
now
,
"
yyyy-mm-dd hh:mm:ss.l
"
);
this
.
firehose
.
putRecord
(
telemetry
)
.
then
(()
=>
{
...
...
providers/provider.js
View file @
cba91305
...
...
@@ -2,7 +2,15 @@
const
AWSProvider
=
require
(
'
./aws.js
'
);
/**
* A Cloud Provider object for a calling script to refer to.
*/
class
Provider
{
/**
* Takes in a full config object (see config.json.sample).
* Constructs a Provider based on the "cloudProvider" key in config.
* Sets the Provider's concrete strategy if valid.
*/
constructor
(
config
)
{
if
(
typeof
config
.
cloudProvider
===
'
undefined
'
||
Object
.
keys
(
config
.
cloudProvider
).
length
===
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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