-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (52 loc) · 1.46 KB
/
app.js
File metadata and controls
62 lines (52 loc) · 1.46 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
61
62
var express = require("express");
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/zombies');
var sensorListSchema = {
unit_id: Number,
location: String,
type: String
}
var SensorList = mongoose.model('SensorList', sensorListSchema, 'sensors');
var app = express();
// List all the sensors
app.get('/listSensors', function (req, res) {
SensorList.find(function (err, doc) {
res.send(doc);
});
});
app.get('/sensorLocation/:unit_id', function (req, res) {
SensorList.find({ unit_id: req.param('unit_id') }, function(err, sensor) {
if (err) throw err;
// object of the user
console.log(sensor);
res.send(sensor[0].location);
});
});
app.get('/sendDrone/:location', function (req, res) {
var RollingSpider = require("rolling-spider"),
temporal = require("temporal"),
drone = new RollingSpider();
drone.connect(function() {
drone.setup(function() {
temporal.queue([
{
delay: 0,
task: function () {
drone.flatTrim();
drone.startPing();
console.log('connected!');
drone.takeOff();
}
},
{
delay: 4000,
task: function() {
console.log('landing!');
drone.land();
}
}]);
});
});
res.send("Sending drone to " + req.param('location'));
});
app.listen(8080);