add weather to homePage
This commit is contained in:
parent
a262fef79c
commit
9deee5663d
@ -92,5 +92,10 @@ module.exports = {
|
|||||||
piHolePage: async (domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked) => {
|
piHolePage: async (domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked) => {
|
||||||
lcd.printLineSync(2, 'Queries=' + commaNumber(queriesToday))
|
lcd.printLineSync(2, 'Queries=' + commaNumber(queriesToday))
|
||||||
lcd.printLineSync(3, 'Blocked=' + commaNumber(queriesBlockedToday) + ' (' + percentageBlocked.toFixed() + '%)')
|
lcd.printLineSync(3, 'Blocked=' + commaNumber(queriesBlockedToday) + ' (' + percentageBlocked.toFixed() + '%)')
|
||||||
|
},
|
||||||
|
weather: async (city, weatherDescription, currentTemp, highTemp, lowTemp) => {
|
||||||
|
weatherDescription = weatherDescription.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase());
|
||||||
|
lcd.printLineSync(2, weatherDescription + ' - ' + currentTemp + '\xDF')
|
||||||
|
lcd.printLineSync(3, 'High-' + highTemp + '\xDF' + ' / ' + 'Low-' + lowTemp + '\xDF')
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ module.exports = {
|
|||||||
await screen.clearLine(3)
|
await screen.clearLine(3)
|
||||||
await screen.clearLine(4)
|
await screen.clearLine(4)
|
||||||
await screen.time()
|
await screen.time()
|
||||||
|
await modules.weather.getStatus()
|
||||||
},
|
},
|
||||||
water: async () => {
|
water: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
clearInterval(globalVars.waterPolling);
|
||||||
@ -54,5 +55,5 @@ module.exports = {
|
|||||||
globalVars.piHolePolling = setInterval(() => {
|
globalVars.piHolePolling = setInterval(() => {
|
||||||
modules.pihole.getStatus()
|
modules.pihole.getStatus()
|
||||||
}, 30000);
|
}, 30000);
|
||||||
}
|
},
|
||||||
}
|
}
|
50
modules/weather.js
Normal file
50
modules/weather.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
const http = require('http')
|
||||||
|
const globalVars = require('../libs/globalVars')
|
||||||
|
const led = require('../libs/led')
|
||||||
|
const common = require('../libs/common')
|
||||||
|
const lcd = require('../libs/lcd')
|
||||||
|
|
||||||
|
const city = "Basingstoke"
|
||||||
|
const appid = "ba24c6018ddd72041749018d0c1b1ef8"
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
getStatus: () => {
|
||||||
|
var rest_options = {
|
||||||
|
host: 'api.openweathermap.org',
|
||||||
|
port: 80,
|
||||||
|
path: '/data/2.5/weather?q=' + city + '&appid=' + appid + '&units=metric',
|
||||||
|
method: 'GET'
|
||||||
|
};
|
||||||
|
let t = new Date().toUTCString()
|
||||||
|
console.log(t + ' piHole request')
|
||||||
|
var request = http.request(rest_options, function (response) {
|
||||||
|
var content = "";
|
||||||
|
|
||||||
|
// Handle data chunks
|
||||||
|
response.on('data', function (chunk) {
|
||||||
|
content += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Once we're done streaming the response, parse it as json.
|
||||||
|
response.on('end', async function () {
|
||||||
|
var data = JSON.parse(content);
|
||||||
|
let city = data.name
|
||||||
|
let weatherDescription = data.weather[0].description
|
||||||
|
let currentTemp = Math.floor(data.main.temp)
|
||||||
|
let highTemp = Math.floor(data.main.temp_max)
|
||||||
|
let lowTemp = Math.floor(data.main.temp_min)
|
||||||
|
|
||||||
|
await lcd.weather(city, weatherDescription, currentTemp, highTemp, lowTemp)
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
// Report errors
|
||||||
|
request.on('error', function (error) {
|
||||||
|
led.set('green')
|
||||||
|
lcd.heatingStatus('Error No Data')
|
||||||
|
globalVars.heatingOn = 'error'
|
||||||
|
});
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user