-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.js
More file actions
88 lines (78 loc) · 2.58 KB
/
Copy pathexport.js
File metadata and controls
88 lines (78 loc) · 2.58 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var date_graph = [];
var humi_graph = [];
var temp_graph = [];
var bodyTemp_graph = [];
var eco2_graph = [];
function exportChart(con, io) {
var m_time
var newTemp
var newHumi
var newBodyTemp
var newEco2
var sql1 = "SELECT * FROM sensors20 ORDER BY ID DESC limit 1"
con.query(sql1, function (err, result, fields) {
if (err) throw err;
console.log("Data selected");
result.forEach(function (value) {
m_time = value.Time.toString().slice(4, 24);
newTemp = value.Temperature
newHumi = value.Humidity
newBodyTemp = value.bodytemp
newEco2 = value.eCO2
console.log(m_time + " " + value.Temperature + " " + value.Humidity + " " + value.BodyTemp + " " + value.Eco2);
io.sockets.emit('server-update-data',
{ id: value.ID, time: m_time, temp: value.Temperature, humi: value.Humidity, bodyTemp: value.bodytemp, eco2: value.eCO2})
})
if (humi_graph.length < 20) {
humi_graph.push(newHumi);
}
else {
for (i = 0; i < 19; i++) {
humi_graph[i] = humi_graph[i + 1];
}
humi_graph[19] = newHumi;
}
if (temp_graph.length < 20) {
temp_graph.push(newTemp);
}
else {
for (u = 0; u < 19; u++) {
temp_graph[u] = temp_graph[u + 1];
}
temp_graph[19] = newTemp;
}
if (date_graph.length < 20) {
date_graph.push(m_time);
}
else {
for (x = 0; x < 19; x++) {
date_graph[x] = date_graph[x + 1];
}
date_graph[19] = m_time;
}
if (bodyTemp_graph.length < 20) {
bodyTemp_graph.push(newBodyTemp);
}
else {
for (x = 0; x < 19; x++) {
bodyTemp_graph[x] = bodyTemp_graph[x + 1];
}
bodyTemp_graph[19] = newBodyTemp;
}
if (eco2_graph.length < 20) {
eco2_graph.push(newEco2);
}
else {
for (x = 0; x < 19; x++) {
eco2_graph[x] = eco2_graph[x + 1];
}
eco2_graph[19] = newEco2;
}
io.sockets.emit("server-send-humi_graph", humi_graph);
io.sockets.emit("server-send-temp_graph", temp_graph);
io.sockets.emit("server-send-date_graph", date_graph);
io.sockets.emit("server-send-bodyTemp_graph", bodyTemp_graph);
io.sockets.emit("server-send-eco2_graph", eco2_graph);
});
}
module.exports = exportChart