-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvd_controller.js
38 lines (31 loc) · 1.02 KB
/
vd_controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const format = require("date-fns/format");
const mqtt_connect = require("../consumer")
const { db } = require("../databases/sqlite")
let VD_Open = []
let VD_Close = []
const gateOpen = async (guid, data) => {
VD_Open.unshift(data)
if (VD_Open.length == 3) {
VD_Open.pop()
}
if (VD_Open[0] == '0' && VD_Open[1] == '1') {
db.all("SELECT * FROM activityiot WHERE input_guid = ?", [guid], async (err, activity) => {
await mqtt_connect.publish('Gate-Open', activity[0].output_guid + "#" + activity[0].output_value)
})
}
}
const gateClose = async (guid, data) => {
VD_Close.unshift(data)
if (VD_Close.length == 3) {
VD_Close.pop()
}
if (VD_Close[0] == '0' && VD_Close[1] == '1') {
db.all("SELECT * FROM activityiot WHERE input_guid = ?", [guid], async (err, activity) => {
await mqtt_connect.publish('Gate-Close', activity[0].output_guid + "#" + activity[0].output_value)
})
}
}
module.exports = {
gateOpen,
gateClose
}