-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor
50 lines (37 loc) · 1016 Bytes
/
sensor
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 http = require("http");
var requestObject = {
url: "http://api.dronesmith.io/api/drone/elegant_brattain/sensor/sound_sensor",
headers: {
'user-key': '3824a348-8048-4593-840a-fc785d214415',
'user-email': 'atthack@dronesmith.io'
}
}
var res = http.request(requestObject);
var reading = [Date.now(), JSON.parse(res.body).intensity];
var documents = require("document");
var record = documents.get("readings");
var now = new Date().valueOf();
if (record.metadata.status == "success") {
}
// record the current record
var fields = {
"key": "readings",
"timestamp": now,
"meta.types": {
"timestamp": "numeric"
}
};
if (duration) {
fields.duration = duration;
fields["meta.types"].duration = "numeric";
}
if (lastDuration) {
fields.lastDuration = lastDuration;
fields["meta.types"].lastDuration = "numeric";
}
documents.save(fields);
if (!storage.local.sensor) {
storage.local.sensor = [];
}
storage.local.sensor.push(reading);
return storage.local.sensor;