-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (57 loc) · 1.74 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
var express = require('express');
var app = express();
var http = require('http').Server(app);
var path = require('path');
var exphbs = require('express-handlebars');
var io = require('socket.io')(http);
var common = require('./helpers/common');
var cors = require('cors');
var gpio = require('gpio');
//SW-420 Sensor GPIO//////////////////////////////////////////////////////////////////////////////////////
var gpio14 = gpio.export(4, {
direction: "in",
ready: function() {
}
});
gpio14.on("change", function(val) {
console.log("Value changed, new value is: " + val);
});
function readInput() {
console.log('The value is: ' + gpio14.value);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Start CPU Temp Logging
var cpuTempLogInterval = 1000;
setInterval(function(){
common.logCurrentCPUTemperature(400, io);
readInput();
}, cpuTempLogInterval);
//TODO:Add GPIO package for Raspberry PI
//var gpio = require('rpi-gpio');
io.on('connection',function(socket){
console.log("A user is connected on main.js");
});
//Express Routers
var diagnosticsRouter = require('./routes/diagnostics')(io);
var hbs = exphbs.create({
defaultLayout: "main",
extname: "html",
helpers: {
section: function (name, options) {
if (!this._sections) this._sections = {};
this._sections[name] = options.fn(this);
return null;
}
}
});
app.use(cors());
app.engine('html', hbs.engine);
app.set('view engine', 'html');
app.use(function timeLog (req, res, next) {
console.log('Request time: ', Date.now());
next();
});
app.use('/diagnostics', diagnosticsRouter);
http.listen(3000, function () {
console.log('listening on *:3000');
});