-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (43 loc) · 1.28 KB
/
main.js
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
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
var constants = require('./constants');
var Temperature = require('./devices/temperature');
var Noise = require('./devices/noise');
var AirQuality = require('./devices/airQuality');
var Motion = require('./devices/motion');
var display = require('./devices/display');
var api = require('./api');
var lcd = require('jsupm_i2clcd');
var devices = [
new Temperature(),
new Noise(),
new AirQuality(),
new Motion()
];
display.showInitScreen();
reportDevices();
function reportDevices() {
var reports = [];
display.clearScreen();
for (var batchCounter = 0; batchCounter < constants.reportinBatchSize; batchCounter++) {
display.showCollectingScreen(batchCounter, constants.reportinBatchSize);
reports.push(getReport());
}
display.showSendingScreen();
api.sendReport(reports).then(function() {
display.showSchedulingScreen();
setTimeout(reportDevices, 500);
}).catch(function(){
display.showErrorScreen();
setTimeout(reportDevices, 500);
});
}
function getReport() {
var report = {
date: new Date().toISOString()
};
devices.forEach(function(device) {
report = Object.assign(report, device.getData());
});
return report;
}