박권수

feat. server on -> all of mqtt client on Util

1 +const Mqtt = require('../lib/MqttModule');
2 +const DataProcess = require('../lib/DataProcess');
3 +const Hub = require('../models/hub');
4 +const Bottle = require('../models/bottle');
5 +
6 +exports.on = async() => {
7 + await subscribeOn();
8 + console.log('\x1b[1;34mMQTT Server On\x1b[0m');
9 +};
10 +
11 +const subscribeOn = async () => {
12 + const bottleList = await Bottle.find();
13 +
14 + bottleList.forEach(async(bottle) => {
15 + const topic = 'bottle/' + bottle.getBottleId() + '/bts';
16 + const hub = await Hub.findByHubId(bottle.getHubId());
17 + const client = await Mqtt.mqttOn(hub.getHubHost(), DataProcess.dataPublish);
18 + Mqtt.mqttSubscribe(client, topic);
19 + })
20 +};
...\ No newline at end of file ...\ No newline at end of file