Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
A
augustctl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
open-source
augustctl
Commits
8f7cb3bb
Verified
Commit
8f7cb3bb
authored
Aug 28, 2016
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure helpers have access to all necessary varibles
parent
ddb50090
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
10 deletions
+12
-10
server.js
server.js
+12
-10
No files found.
server.js
View file @
8f7cb3bb
...
...
@@ -34,7 +34,7 @@ var ret = {
};
// Get lock instance
function
getLockInstance
(
lockName
)
{
function
getLockInstance
(
lockName
,
res
)
{
var
lock
=
app
.
get
(
'
lock
'
+
lockName
);
if
(
lock
)
{
return
lock
;
...
...
@@ -68,8 +68,8 @@ function clearCaches( lockName ) {
}
// Reset lock connection
function
disconnectAndClear
(
lockName
)
{
var
lock
=
getLockInstance
(
lockName
);
function
disconnectAndClear
(
lockName
,
res
)
{
var
lock
=
getLockInstance
(
lockName
,
res
);
if
(
!
lock
)
{
return
;
}
...
...
@@ -85,7 +85,7 @@ function disconnectAndClear( lockName ) {
// Endpoint to check lock status
app
.
get
(
'
/api/status/:lock_name
'
,
cache
(
'
5 seconds
'
),
function
(
req
,
res
)
{
// Parse allowed request arguments
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
,
res
);
if
(
!
lock
)
{
return
;
}
...
...
@@ -105,7 +105,7 @@ app.get( '/api/status/:lock_name', cache( '5 seconds' ), function( req, res ) {
// Perform requested action
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
console
.
error
(
err
);
disconnectAndClear
(
req
.
params
.
lock_name
);
disconnectAndClear
(
req
.
params
.
lock_name
,
res
);
res
.
sendStatus
(
500
);
}
);
}
);
...
...
@@ -121,7 +121,7 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '3 seconds' ), func
}
var
lockName
=
req
.
params
.
lock_name
,
lock
=
getLockInstance
(
lockName
);
lock
=
getLockInstance
(
lockName
,
res
);
if
(
!
lock
)
{
return
;
}
...
...
@@ -148,14 +148,14 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '3 seconds' ), func
ret
.
msg
=
"
No change made. Lock was already '
"
+
status
+
"
'.
"
;
}
disconnectAndClear
(
lockName
);
disconnectAndClear
(
lockName
,
res
);
res
.
json
(
ret
);
}
);
// Perform requested action
lock
.
connect
().
then
(
actionFunction
).
catch
(
function
(
err
)
{
console
.
error
(
err
);
disconnectAndClear
(
lockName
);
disconnectAndClear
(
lockName
,
res
);
res
.
sendStatus
(
500
);
}
);
}
);
...
...
@@ -163,12 +163,12 @@ app.get( '/api/:lock_action(lock|unlock)/:lock_name', cache( '3 seconds' ), func
// Endpoint to disconnect a lock's BLE connections
app
.
get
(
'
/api/disconnect/:lock_name
'
,
function
(
req
,
res
)
{
// Parse allowed request arguments
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
);
var
lock
=
getLockInstance
(
req
.
params
.
lock_name
,
res
);
if
(
!
lock
)
{
return
;
}
disconnectAndClear
(
req
.
params
.
lock_name
);
disconnectAndClear
(
req
.
params
.
lock_name
,
res
);
res
.
sendStatus
(
204
);
}
);
...
...
@@ -180,6 +180,8 @@ app.get( '/api/disconnect/:lock_name', function( req, res ) {
Object
.
keys
(
config
).
forEach
(
function
(
lockName
)
{
var
lockConfig
=
config
[
lockName
];
console
.
log
(
'
Loading config for lock %s
'
,
lockConfig
.
lockUuid
);
augustctl
.
scan
(
lockConfig
.
lockUuid
).
then
(
function
(
peripheral
)
{
var
lock
=
new
augustctl
.
Lock
(
peripheral
,
...
...
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