박권수

feat. hub control logic going dev

...@@ -3,26 +3,20 @@ const Hub = require('../../models/hub'); ...@@ -3,26 +3,20 @@ const Hub = require('../../models/hub');
3 const Mqtt = require('../../lib/MqttModule'); 3 const Mqtt = require('../../lib/MqttModule');
4 4
5 exports.hubConnect = async (ctx) => { 5 exports.hubConnect = async (ctx) => {
6 - const { host, port, hubId, topic } = ctx.request.body; 6 + const { host, port, hubId } = ctx.request.body;
7 7
8 - const hub = { 8 + const hosting = {
9 - hubId, 9 + host,
10 - hosting : { 10 + port
11 - host,
12 - port
13 - }
14 }; 11 };
15 12
16 - await Hub.findOneAndUpdate({ 13 + Mqtt.mqttOn(hosting);
17 - hubId 14 + await Hub.findOneAndUpdate({
18 - }, hub, { 15 + hubId
16 + }, { hosting }, {
19 upsert : true 17 upsert : true
20 }); 18 });
21 19
22 - const client = Mqtt.mqttOn({ host, port });
23 - Mqtt.mqttSubscribe(client, topic);
24 -
25 - ctx.body = 'host :' + host;
26 ctx.status = 200; 20 ctx.status = 200;
27 } 21 }
28 22
......