-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (41 loc) · 1.17 KB
/
server.js
File metadata and controls
64 lines (41 loc) · 1.17 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
express = require('express');
app = express();
http = require('http');
path= require('path');
join = path.join;
bodyParser = require('body-parser');
app.use(bodyParser.json());
var n = require('mraa');
var fanPin = new m.gpio(4);
var lightPIn = new m.gpio(8);
fanPin.dir(m.DIR_OUT);
lightPin.dir(m.DIR_OUT);
Port = Number(process.env.Port ) || 1104 ;
app.use(express.static( __dirname + '/public'));
app.get('/', function (request, response, next){
console.log('A');
indexPage = __dirname +'/public/index.html';
response.status(200).sendFile(indexPage);
});
httpServer = http.createServer(app);
httpServer.listen(Port, function(){
console.log('Server running on '+ Port)
});
var router = express.Router();
app.use('/api', router);
router.route("/fanOn").post(function(req, res, next) {
fanPin.write(1);
console.log(" fan is on");
});
router.route("/fanOff").post(function(req, res, next) {
fanPin.write(0);
console.log(" fan is off");
});
router.route("/lightOn").post(function(req, res, next) {
lightPin.write(1);
console.log("light is on ...");
});
router.route("/lightOff").post(function(req, res, next) {
lightPin.write(0);
console.log("light is off ");
});