박권수

feat. medicine disconnect logic add

......@@ -5,9 +5,9 @@ const Medicine = require('../../models/medicine');
const DataProcess = require('../../lib/DataProcess');
const Mqtt = require('../../lib/MqttModule');
exports.bottleRegister = async(ctx) => {
exports.bottleConnect = async(ctx) => {
const { bottleId, hubId } = ctx.request.body;
const topic = 'bottle/' + String(bottleId) + '/bts';
const topic = 'bottle/' + bottleId + '/bts';
const newBottle = new Bottle({
bottleId,
......@@ -37,6 +37,7 @@ exports.bottleRegister = async(ctx) => {
port : hosting.port,
clientId : hosting.clientId
});
Mqtt.mqttSubscribe(client, topic, DataProcess.dataPublish);
await newBottle.save();
......@@ -44,6 +45,10 @@ exports.bottleRegister = async(ctx) => {
ctx.status = 200;
};
exports.bottleDisconnect = async(ctx) => {
const { bottleId } = ctx.params;
};
exports.lookupInfo = async(ctx) => {
const { bottleId } = ctx.params;
......@@ -53,6 +58,7 @@ exports.lookupInfo = async(ctx) => {
return;
}
ctx.status = 200;
ctx.body = bottle;
}
......
......@@ -3,7 +3,8 @@ const bottleCtrl = require('./bottle.ctrl');
const bottle = new Router();
bottle.post('/register', bottleCtrl.bottleRegister);
bottle.post('/connect', bottleCtrl.bottleConnect);
bottle.post('/disconnect/:bottleId', bottleCtrl.bottleDisconnect);
bottle.post('/lookupInfo/:bottleId', bottleCtrl.lookupInfo);
bottle.post('/setmedicine/:bottleId', bottleCtrl.setMedicine);
......