Showing
2 changed files
with
10 additions
and
3 deletions
... | @@ -5,9 +5,9 @@ const Medicine = require('../../models/medicine'); | ... | @@ -5,9 +5,9 @@ const Medicine = require('../../models/medicine'); |
5 | const DataProcess = require('../../lib/DataProcess'); | 5 | const DataProcess = require('../../lib/DataProcess'); |
6 | const Mqtt = require('../../lib/MqttModule'); | 6 | const Mqtt = require('../../lib/MqttModule'); |
7 | 7 | ||
8 | -exports.bottleRegister = async(ctx) => { | 8 | +exports.bottleConnect = async(ctx) => { |
9 | const { bottleId, hubId } = ctx.request.body; | 9 | const { bottleId, hubId } = ctx.request.body; |
10 | - const topic = 'bottle/' + String(bottleId) + '/bts'; | 10 | + const topic = 'bottle/' + bottleId + '/bts'; |
11 | 11 | ||
12 | const newBottle = new Bottle({ | 12 | const newBottle = new Bottle({ |
13 | bottleId, | 13 | bottleId, |
... | @@ -37,6 +37,7 @@ exports.bottleRegister = async(ctx) => { | ... | @@ -37,6 +37,7 @@ exports.bottleRegister = async(ctx) => { |
37 | port : hosting.port, | 37 | port : hosting.port, |
38 | clientId : hosting.clientId | 38 | clientId : hosting.clientId |
39 | }); | 39 | }); |
40 | + | ||
40 | Mqtt.mqttSubscribe(client, topic, DataProcess.dataPublish); | 41 | Mqtt.mqttSubscribe(client, topic, DataProcess.dataPublish); |
41 | 42 | ||
42 | await newBottle.save(); | 43 | await newBottle.save(); |
... | @@ -44,6 +45,10 @@ exports.bottleRegister = async(ctx) => { | ... | @@ -44,6 +45,10 @@ exports.bottleRegister = async(ctx) => { |
44 | ctx.status = 200; | 45 | ctx.status = 200; |
45 | }; | 46 | }; |
46 | 47 | ||
48 | +exports.bottleDisconnect = async(ctx) => { | ||
49 | + const { bottleId } = ctx.params; | ||
50 | +}; | ||
51 | + | ||
47 | exports.lookupInfo = async(ctx) => { | 52 | exports.lookupInfo = async(ctx) => { |
48 | const { bottleId } = ctx.params; | 53 | const { bottleId } = ctx.params; |
49 | 54 | ||
... | @@ -53,6 +58,7 @@ exports.lookupInfo = async(ctx) => { | ... | @@ -53,6 +58,7 @@ exports.lookupInfo = async(ctx) => { |
53 | return; | 58 | return; |
54 | } | 59 | } |
55 | 60 | ||
61 | + ctx.status = 200; | ||
56 | ctx.body = bottle; | 62 | ctx.body = bottle; |
57 | } | 63 | } |
58 | 64 | ... | ... |
... | @@ -3,7 +3,8 @@ const bottleCtrl = require('./bottle.ctrl'); | ... | @@ -3,7 +3,8 @@ const bottleCtrl = require('./bottle.ctrl'); |
3 | 3 | ||
4 | const bottle = new Router(); | 4 | const bottle = new Router(); |
5 | 5 | ||
6 | -bottle.post('/register', bottleCtrl.bottleRegister); | 6 | +bottle.post('/connect', bottleCtrl.bottleConnect); |
7 | +bottle.post('/disconnect/:bottleId', bottleCtrl.bottleDisconnect); | ||
7 | bottle.post('/lookupInfo/:bottleId', bottleCtrl.lookupInfo); | 8 | bottle.post('/lookupInfo/:bottleId', bottleCtrl.lookupInfo); |
8 | bottle.post('/setmedicine/:bottleId', bottleCtrl.setMedicine); | 9 | bottle.post('/setmedicine/:bottleId', bottleCtrl.setMedicine); |
9 | 10 | ... | ... |
-
Please register or login to post a comment