-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
89 lines (76 loc) · 1.64 KB
/
server.js
File metadata and controls
89 lines (76 loc) · 1.64 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Device server for the OWG initiative.
Written in NodeJS + Express + Sockets.io.
@author Sergio Diaz
*/
// Requires.
var express = require('express');
var app = express();
/**
* Server and sensor status probe.
* @return {string} [JSON containing status information]
*/
app.get('/status', function (req, res) {
var status = {
server: true,
sensors: true,
success: true
}
// return the stringified json
res.send(JSON.stringify(status));
});
/**
* Returns current information from sensors in JSON format.
* A preffered method to access current data is using sockets for each
* sensor, but sometimes in the frontend this is needed.
*
* @return {string} [JSON containing current information]
*/
app.get('/now', function(req, res) {
var sensor_data = {
temperature_f: 20,
temperature_c: 20,
humidity: 10,
pressure: 10,
time: Date.now(),
success: true
};
// return the json
res.send(JSON.stringify(sensor_data));
});
/**
* Returns raw sensor data.
* @return {string} [JSON containing sensor data.]
*/
app.get('/sensors/:sensor', function(req, res) {
var sensor = req.params.sensor;
switch (sensor) {
case 'temperature':
data = 20;
break;
case 'humidity':
data = 10;
break;
case 'pressure':
data = 10;
break;
}
sensor_data = {
data: data,
time: Date.now(),
success: true
}
// return the json
res.send(JSON.stringify(sensor_data));
});
/**
* Returns current sensor location.
* @return {string} [JSON containing sensor data.]
*/
app.get('/location', function(req, res) {
// TODO
res.send("latlong");
});
app.listen(8080, function () {
console.log('OWGI server running on 8080...');
});