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
3c6190d1
Verified
Commit
3c6190d1
authored
Aug 21, 2016
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add multiple-lock support to server
parent
19be5539
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
23 deletions
+24
-23
server-config.json
server-config.json
+1
-0
server.js
server.js
+23
-23
No files found.
server-config.json
0 → 100644
View file @
3c6190d1
{
"address"
:
'localhost'
,
"port"
:
3000
}
server.js
View file @
3c6190d1
...
...
@@ -6,18 +6,19 @@ var morgan = require('morgan');
var
await
=
require
(
'
asyncawait/await
'
);
var
async
=
require
(
'
asyncawait/async
'
);
var
config
=
require
(
process
.
env
.
AUGUSTCTL_CONFIG
||
'
./config.json
'
);
var
serverConfig
=
require
(
process
.
env
.
AUGUSTCTL_SERVER_CONFIG
||
'
./server-config.json
'
);
var
DEBUG
=
process
.
env
.
NODE_ENV
!==
'
production
'
;
var
address
=
c
onfig
.
address
||
'
localhost
'
;
var
port
=
c
onfig
.
port
||
3000
;
var
address
=
serverC
onfig
.
address
||
'
localhost
'
;
var
port
=
serverC
onfig
.
port
||
3000
;
var
app
=
express
();
app
.
use
(
morgan
(
DEBUG
?
'
dev
'
:
'
combined
'
));
var
ret
=
{
'
status
'
:
-
1
,
'
ret
'
:
''
,
'
msg
'
:
''
};
app
.
get
(
'
/api/unlock
'
,
function
(
req
,
res
)
{
var
lock
=
app
.
get
(
'
lock
'
);
app
.
get
(
'
/api/unlock
/:lock_name
'
,
function
(
req
,
res
)
{
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
if
(
!
lock
)
{
res
.
sendStatus
(
503
);
return
;
...
...
@@ -39,7 +40,7 @@ var execStatus = async(function() {
}
else
{
{
ret
[
'
status
'
]
=
1
;
ret
[
'
msg
'
]
=
'
Lock is already unlocked
'
;
res
.
json
(
ret
);
...
...
@@ -56,13 +57,13 @@ var execStatus = async(function() {
}).
catch
(
function
(
e
)
{
console
.
error
(
e
.
toString
());
});
});
});
app
.
get
(
'
/api/lock
'
,
function
(
req
,
res
)
{
var
lock
=
app
.
get
(
'
lock
'
);
app
.
get
(
'
/api/lock
/:lock_name
'
,
function
(
req
,
res
)
{
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
if
(
!
lock
)
{
res
.
sendStatus
(
503
);
return
;
...
...
@@ -83,7 +84,7 @@ app.get('/api/lock', function(req, res) {
}
else
{
{
ret
[
'
status
'
]
=
1
;
ret
[
'
msg
'
]
=
'
Lock is already locked
'
;
...
...
@@ -99,14 +100,13 @@ app.get('/api/lock', function(req, res) {
}).
finally
(
function
(){
console
.
log
(
'
Finally
'
);
});
});
});
app
.
get
(
'
/api/status
'
,
function
(
req
,
res
){
var
lock
=
app
.
get
(
'
lock
'
);
app
.
get
(
'
/api/status/:lock_name
'
,
function
(
req
,
res
){
var
lock
=
app
.
get
(
'
lock
'
+
req
.
params
.
lock_name
);
if
(
!
lock
)
{
res
.
sendStatus
(
503
);
return
;
...
...
@@ -128,7 +128,7 @@ app.get('/api/status', function(req, res){
lock
.
connect
().
then
(
function
()
{
var
status
=
execStatus
();
}).
finally
(
function
()
{
console
.
log
(
'
Finally
'
);
});
...
...
@@ -136,16 +136,16 @@ app.get('/api/status', function(req, res){
});
augustctl
.
scan
(
config
.
lockUuid
).
then
(
function
(
peripheral
)
{
var
lock
=
new
augustctl
.
Lock
(
peripheral
,
config
.
offlineKey
,
config
.
offlineKeyOffset
);
app
.
set
(
'
lock
'
,
lock
);
config
.
forEach
(
function
(
lockConfig
,
lockName
)
{
augustctl
.
scan
(
lockConfig
.
lockUuid
).
then
(
function
(
peripheral
)
{
var
lock
=
new
augustctl
.
Lock
(
peripheral
,
lockConfig
.
offlineKey
,
lockConfig
.
offlineKeyOffset
);
app
.
set
(
'
lock
'
+
lockName
,
lock
);
});
});
var
server
=
app
.
listen
(
port
,
address
,
function
()
{
console
.
log
(
'
Listening at %j
'
,
server
.
address
());
});
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