Showing
1 changed file
with
4 additions
and
10 deletions
... | @@ -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, | ||
10 | - hosting : { | ||
11 | host, | 9 | host, |
12 | port | 10 | port |
13 | - } | ||
14 | }; | 11 | }; |
15 | 12 | ||
13 | + Mqtt.mqttOn(hosting); | ||
16 | await Hub.findOneAndUpdate({ | 14 | await Hub.findOneAndUpdate({ |
17 | hubId | 15 | hubId |
18 | - }, hub, { | 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 | ... | ... |
-
Please register or login to post a comment