-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotoPiServer.js
More file actions
52 lines (39 loc) · 875 Bytes
/
MotoPiServer.js
File metadata and controls
52 lines (39 loc) · 875 Bytes
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
var express = require('express');
var app = express();
var port = process.env.PORT || 500;
var MotoPi = require('./MotoPi.js');
var client = function(req, res){
res.sendfile(__dirname + '/motopi_client.html');
};
var forward = function(req, res){
MotoPi.moveForward();
res.end('DONE');
};
var backward = function(req, res){
MotoPi.moveBackward();
res.end('DONE');
};
var left = function(req, res){
MotoPi.turnLeft();
res.end('DONE');
};
var right = function(req, res){
MotoPi.turnRight();
res.end('DONE');
};
var stop = function(req, res){
MotoPi.stop();
res.end('DONE');
};
exports.start = function()
{
app.get('/forward/',forward);
app.get('/backward/', backward);
app.get('/left/', left);
app.get('/right/', right);
app.get('/stop/', stop);
//Serve the UI
app.get('/', client);
console.log('Listening to port 5000');
app.listen(port);
}