forked from bensternthal/openweather-influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (31 loc) · 1.05 KB
/
app.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
require('dotenv').config();
const Influx = require('./lib/influx');
const InfluxAqi = require('./lib/InfluxAqi');
const Weather = require('./lib/weather');
const Aqi = require('./lib/aqi');
console.log("Starting openweather-influxdb...")
let updateFrequency = process.env.UPDATE_FREQUENCY;
let updateFrequencyAqi = process.env.UPDATE_FREQUENCY_AQI;
function getData() {
Weather.getData().then(Influx.writeInflux).then(function() {
setTimeout(getData, updateFrequency);
}).catch(function(e) {
console.log('Error: ' + e.message);
// Retry on error, but timeout for 5 minutes
setTimeout(getData, 300000);
});
};
function getAqiData() {
Aqi.getAqiData().then(InfluxAqi.writeInfluxAqi).then(function() {
setTimeout(getAqiData, updateFrequencyAqi);
}).catch(function(e) {
console.log('Error: ' + e.message);
// Retry on error, but timeout for 5 minutes
setTimeout(getAqiData, 300000);
});
};
// Start after 10 seconds
setTimeout(function() {
getData();
getAqiData();
}, 10000);