박권수

feat. Data Processing Logic

1 -exports.processing = async(data) => { 1 +const Bottle = require('../models/bottle');
2 2
3 +//Hub topic : bottle/bottleId
4 +//Hub로부터 받은 message : 개폐여부/온도/습도/초음파센서
5 +exports.factoring = (topic, message) => {
6 + const bottleId = topic.split('/')[1];
7 + const data = message.split('/');
8 + const [isOpen, temperature, humidity, balance] = data;
9 +
10 + const openDate = new Date();
11 +
12 + return {
13 + bottleId,
14 + isOpen,
15 + openDate,
16 + temperature,
17 + humidity,
18 + balance
19 + };
20 +}
21 +
22 +//bottleId가 포함된 data를 받아서 해당 약병의 data를 업데이트한다.
23 +exports.bottleInfoUpdate = async(data) => {
24 + const { bottleId, isOpen, openDate, temperature, humidity, balance } = data;
25 + if(isOpen === '1') {
26 + await Bottle.findOneAndUpdate({
27 + bottleId
28 + }, { recentOpen : openDate }, {
29 + new : true
30 + });
31 + }
32 +
33 + await Bottle.findByIdAndUpdate({
34 + bottleId
35 + }, {
36 + temperature,
37 + humidity,
38 + balance
39 + }, { new : true });
40 +}
41 +
42 +//해당 MQTT Broker(client)에 bottleId의 정보에 관한 message를 발행한다.
43 +exports.dataPublishg = (client, bottleId) => {
44 +
3 } 45 }
...\ No newline at end of file ...\ No newline at end of file
......