Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design1
/
RIT_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박권수
2021-05-10 03:25:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
795b6b2b834d61e52e68ae9e855f23c7756c2568
795b6b2b
1 parent
d612f2a5
feat. bottle control logic
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
server/src/api/bottle/bottle.ctrl.js
server/src/api/bottle/index.js
server/src/api/bottle/bottle.ctrl.js
View file @
795b6b2
//어플에서 약병 등록 및, 약병에 관한 정보 조회 = 여기서 mqtt통신으로 broker에 데이터를 요청한다.
const
Bottle
=
require
(
'../../models/bottle'
)
const
Bottle
=
require
(
'../../models/bottle'
);
const
Hub
=
require
(
'../../models/hub'
);
const
DataProcess
=
require
(
'../../lib/DataProcess'
);
const
MqttModule
=
require
(
'../../lib/MqttModule'
);
const
Mqtt
=
require
(
'../../lib/MqttModule'
);
exports
.
bottleRegister
=
async
(
ctx
)
=>
{
const
{
bottleId
,
hubId
,
topic
}
=
ctx
.
request
.
body
;
const
newBottle
=
new
Bottle
({
bottleId
,
hubId
});
const
isExistBottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
if
(
isExistBottle
)
{
ctx
.
status
=
409
;
return
;
}
const
hub
=
await
Hub
.
findByHubId
(
hubId
);
if
(
!
hub
)
{
ctx
.
status
=
404
;
return
;
}
const
hosting
=
await
hub
.
getHubHost
();
if
(
!
hosting
)
{
ctx
.
status
=
404
;
return
;
}
const
client
=
Mqtt
.
mqttOn
({
host
:
hosting
.
host
,
port
:
hosting
.
port
,
clientId
:
hosting
.
clientId
});
Mqtt
.
mqttSubscribe
(
client
,
topic
);
await
newBottle
.
save
();
ctx
.
status
=
200
;
};
exports
.
lookupInfo
=
async
(
ctx
)
=>
{
const
{
bottleId
,
topic
}
=
ctx
.
request
.
body
;
/** toDO
* 약병 데이터를 요청한다
* 1. Broker에 데이터 요청
...
...
@@ -12,6 +52,18 @@ exports.lookupInfo = async(ctx) => {
* 4. 유저에게 http response
*/
const
bottle
=
await
Bottle
.
findByBottleId
(
bottleId
);
const
hubId
=
await
bottle
.
getHubId
();
const
hub
=
await
Hub
.
findByHubId
(
hubId
);
const
hosting
=
await
hub
.
getHubHost
();
const
client
=
await
Mqtt
.
mqttOn
({
host
:
hosting
.
host
,
port
:
hosting
.
port
,
clientId
:
hosting
.
clientId
,
});
Mqtt
.
mqttSubscribe
(
client
,
topic
);
const
a
=
dataRequest
();
//1.
const
b
=
await
getData
();
const
c
=
await
dataProcess
();
...
...
server/src/api/bottle/index.js
View file @
795b6b2
...
...
@@ -3,6 +3,7 @@ const bottleCtrl = require('./bottle.ctrl');
const
bottle
=
new
Router
();
bottle
.
post
(
'/register'
,
bottleCtrl
.
bottleRegister
);
bottle
.
post
(
'/lookupInfo'
,
bottleCtrl
.
lookupInfo
);
bottle
.
post
(
'/setmedicine'
,
bottleCtrl
.
setMedicine
);
...
...
Please
register
or
login
to post a comment