-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (46 loc) · 1.28 KB
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Simple demo for World Weather Online using ajax/jquery/underscore
var express = require("express");
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/tty.usbmodemfd121", {baudrate: 9600, parser: require("serialport").parsers.readline('\n')}, false);
var fs = require('fs');
var concentration = false;
function getDirectories() {
return fs.readdirSync('/dev/').filter(function (file) {
return file.indexOf('tty.usbmodem') > -1;
});
}
if(getDirectories().length > 0)
{
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/" + getDirectories()[0], {baudrate: 9600, parser: require("serialport").parsers.readline('\n')}, false);
console.log("Arduino detected");
serialPort.open(function (error)
{
serialPort.on('data', function(data)
{
if(String(data).indexOf("High") > -1)
{
concentration = true;
}
else
{
concentration = false;
}
});
}
);
}
var app = express();
app.use("", express.static("/Users/Lawrence/Documents/Git\ Hub/Smartbox"));
app.get("/", function(req, res){
if(!concentration)
{
res.sendfile("./index.html");
}
else
{
res.sendfile("./index_concentration.html");
}
});
app.listen(8000);
console.log("listening on port 8000");