-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigger_server.js
37 lines (29 loc) · 1.26 KB
/
trigger_server.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
const http = require('http');
const settings = require('./settings');
exports.listen = function(determineWhoTriggered, getAutomaticNoActionSnapshot, stopAutomaticNoActionSnapshotTimeout) {
const automaticNoActionSnapshotInterval = settings.automaticNoActionSnapshotInterval;
const room = settings.room;
var noActionTimeout = setNoActionTimeout();
http.createServer(function (req, res) {
req.on('data', (data) => {
data = JSON.parse(data);
if (data.hasOwnProperty("sentFrom") && data["sentFrom"] === "sensorPi") {
if (data["room"] === room) {
clearTimeout(noActionTimeout);
stopAutomaticNoActionSnapshotTimeout();
determineWhoTriggered(data);
noActionTimeout = setNoActionTimeout();
res.write('Thank you'); //write a response to the client
res.end(); //end the response
}
}
})
}).listen(8081); //the server object listens on port 8080
function setNoActionTimeout() {
return setTimeout(() => {
console.log("\nNo recent action")
getAutomaticNoActionSnapshot();
}
, automaticNoActionSnapshotInterval);
}
}