working bits
This commit is contained in:
parent
eda16c123b
commit
a262fef79c
59
app.js
59
app.js
@ -11,28 +11,44 @@ async function main() {
|
|||||||
await lcd.intro()
|
await lcd.intro()
|
||||||
menu.home()
|
menu.home()
|
||||||
|
|
||||||
const heatingSwitch = new Gpio('17', 'in', 'both');
|
const functionSwitch = new Gpio('17', 'in', 'both');
|
||||||
const appSwitch = new Gpio('23', 'in', 'both');
|
const appSwitch = new Gpio('23', 'in', 'both');
|
||||||
|
|
||||||
heatingSwitch.watch(async (err, value) => {
|
functionSwitch.watch(async (err, value) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Error', err);
|
console.log('Error', err);
|
||||||
}
|
}
|
||||||
if (value === 1) {
|
if (value === 1) {
|
||||||
console.log('Water Switch')
|
switch (globalVars.currentPage) {
|
||||||
if (globalVars.waterOn === 'true') {
|
case 'water':
|
||||||
await common.request(0)
|
console.log('Water Switch')
|
||||||
await common.pause(2000)
|
if (globalVars.waterOn === 'true') {
|
||||||
menu.water()
|
await common.request(0)
|
||||||
} else {
|
await common.pause(2000)
|
||||||
await common.request(1)
|
await menu.water()
|
||||||
await common.pause(2000)
|
} else {
|
||||||
menu.water()
|
await common.request(1)
|
||||||
|
await common.pause(2000)
|
||||||
|
await menu.water()
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'heating':
|
||||||
|
if (globalVars.heatingPageS === 1) {
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
|
globalVars.heatingPageS = 2
|
||||||
|
} else {
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
|
globalVars.heatingPageS = 1
|
||||||
|
}
|
||||||
|
await menu.heating(globalVars.heatingPageS)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const arr = ['water', 'heating', 'mainMenu']
|
const arr = ['water', 'heating', 'pihole', 'mainMenu']
|
||||||
arrLength = arr.length
|
arrLength = arr.length
|
||||||
let i = 0
|
let i = 0
|
||||||
appSwitch.watch(async (err, value) => {
|
appSwitch.watch(async (err, value) => {
|
||||||
@ -42,18 +58,36 @@ async function main() {
|
|||||||
if (value === 1) {
|
if (value === 1) {
|
||||||
switch (arr[i]) {
|
switch (arr[i]) {
|
||||||
case 'water':
|
case 'water':
|
||||||
|
globalVars.currentPage = arr[i]
|
||||||
|
clearInterval(globalVars.waterPolling)
|
||||||
|
clearInterval(globalVars.heatingPageSwitch)
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
await menu.water()
|
await menu.water()
|
||||||
break;
|
break;
|
||||||
case 'mainMenu':
|
case 'mainMenu':
|
||||||
|
globalVars.currentPage = arr[i]
|
||||||
|
clearInterval(globalVars.waterPolling)
|
||||||
|
clearInterval(globalVars.heatingPageSwitch)
|
||||||
clearInterval(globalVars.heatingPolling)
|
clearInterval(globalVars.heatingPolling)
|
||||||
led.set('off')
|
led.set('off')
|
||||||
await menu.home()
|
await menu.home()
|
||||||
break;
|
break;
|
||||||
case 'heating':
|
case 'heating':
|
||||||
|
globalVars.currentPage = arr[i]
|
||||||
clearInterval(globalVars.waterPolling)
|
clearInterval(globalVars.waterPolling)
|
||||||
|
clearInterval(globalVars.heatingPageSwitch)
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
led.set('off')
|
led.set('off')
|
||||||
await menu.heating()
|
await menu.heating()
|
||||||
break;
|
break;
|
||||||
|
case 'pihole':
|
||||||
|
globalVars.currentPage = arr[i]
|
||||||
|
clearInterval(globalVars.waterPolling)
|
||||||
|
clearInterval(globalVars.heatingPageSwitch)
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
|
led.set('off')
|
||||||
|
await menu.piHole()
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -74,4 +108,5 @@ process.on('SIGINT', function () {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setInterval(lcd.time, 55000)
|
||||||
main()
|
main()
|
@ -4,6 +4,11 @@ class globalVariables {
|
|||||||
waterPolling = "";
|
waterPolling = "";
|
||||||
heatingNextEvent = "";
|
heatingNextEvent = "";
|
||||||
heatingPolling = "";
|
heatingPolling = "";
|
||||||
|
currentPage = "";
|
||||||
|
heatingPageSwitch = "";
|
||||||
|
heatingPageSwitchActive = "";
|
||||||
|
heatingPageS = 1;
|
||||||
|
piHolePolling = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new globalVariables();
|
module.exports = new globalVariables();
|
65
libs/lcd.js
65
libs/lcd.js
@ -2,6 +2,7 @@ const LCD = require('raspberrypi-liquid-crystal');
|
|||||||
const common = require('./common')
|
const common = require('./common')
|
||||||
const globalVars = require('./globalVars')
|
const globalVars = require('./globalVars')
|
||||||
const clock = require('./clock');
|
const clock = require('./clock');
|
||||||
|
var commaNumber = require('comma-number')
|
||||||
|
|
||||||
const lcd = new LCD(1, 0x27, 20, 4);
|
const lcd = new LCD(1, 0x27, 20, 4);
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
intro: async () => {
|
intro: async () => {
|
||||||
lcd.clearSync();
|
lcd.clearSync();
|
||||||
lcd.printLineSync(1, 'MiGenie Status')
|
lcd.printLineSync(1, 'House Status')
|
||||||
lcd.setCursorSync(13, 2);
|
lcd.setCursorSync(13, 2);
|
||||||
lcd.printSync('By Karl')
|
lcd.printSync('By Karl')
|
||||||
await common.pause(3000)
|
await common.pause(3000)
|
||||||
@ -29,7 +30,8 @@ module.exports = {
|
|||||||
lcd.printSync(title)
|
lcd.printSync(title)
|
||||||
},
|
},
|
||||||
time: async () => {
|
time: async () => {
|
||||||
console.log('get time')
|
let t = new Date().toUTCString()
|
||||||
|
console.log(t + ' get time')
|
||||||
lcd.setCursorSync(15, 0);
|
lcd.setCursorSync(15, 0);
|
||||||
lcd.printSync(await clock.time())
|
lcd.printSync(await clock.time())
|
||||||
},
|
},
|
||||||
@ -48,46 +50,47 @@ module.exports = {
|
|||||||
lcd.printSync(input)
|
lcd.printSync(input)
|
||||||
},
|
},
|
||||||
NextEvent: async (input) => {
|
NextEvent: async (input) => {
|
||||||
if (globalVars.waterOn === "true") {
|
if (input === 'Not Set') {
|
||||||
lcd.setCursorSync(0, 3)
|
lcd.setCursorSync(0, 3)
|
||||||
lcd.printSync("Switch Off=")
|
lcd.printSync("Always Off")
|
||||||
lcd.setCursorSync(11, 3);
|
|
||||||
lcd.printSync(' ')
|
|
||||||
lcd.setCursorSync(11, 3);
|
|
||||||
lcd.printSync(input)
|
|
||||||
} else {
|
} else {
|
||||||
lcd.setCursorSync(0, 3)
|
if (globalVars.waterOn === "true") {
|
||||||
lcd.printSync("Switch On=")
|
lcd.setCursorSync(0, 3)
|
||||||
lcd.setCursorSync(10, 3);
|
lcd.printSync("Switch Off=")
|
||||||
lcd.printSync(' ')
|
lcd.setCursorSync(11, 3);
|
||||||
lcd.setCursorSync(10, 3);
|
lcd.printSync(' ')
|
||||||
lcd.printSync(input)
|
lcd.setCursorSync(11, 3);
|
||||||
|
lcd.printSync(input)
|
||||||
|
} else {
|
||||||
|
lcd.setCursorSync(0, 3)
|
||||||
|
lcd.printSync("Switch On=")
|
||||||
|
lcd.setCursorSync(10, 3);
|
||||||
|
lcd.printSync(' ')
|
||||||
|
lcd.setCursorSync(10, 3);
|
||||||
|
lcd.printSync(input)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
currentRoomTemp: async (temp) => {
|
currentRoomTemp: async (temp) => {
|
||||||
lcd.setCursorSync(0, 1);
|
lcd.printLineSync(2, 'Current Temp:' + temp + '\xDF')
|
||||||
let icon = '\xDF'
|
|
||||||
temp = temp + icon
|
|
||||||
lcd.printSync('CT:' + temp);
|
|
||||||
},
|
},
|
||||||
lastSetTemp: async (temp) => {
|
lastSetTemp: async (temp) => {
|
||||||
lcd.setCursorSync(14, 1);
|
lcd.printLineSync(3, 'Last Set Temp:' + temp + '\xDF')
|
||||||
let icon = '\xDF'
|
|
||||||
temp = temp + icon
|
|
||||||
lcd.printSync('LT:' + temp);
|
|
||||||
},
|
},
|
||||||
heatingPageOne: async (heatingStatus, measuredRoomTemp, lastTimerSetPoint, heatingNextEvent) => {
|
heatingPageOne: async (heatingStatus, heatingNextEvent) => {
|
||||||
module.exports.currentRoomTemp(measuredRoomTemp)
|
await module.exports.NextEvent(heatingNextEvent)
|
||||||
module.exports.lastSetTemp(lastTimerSetPoint)
|
await module.exports.heatingStatus(heatingStatus)
|
||||||
module.exports.NextEvent(heatingNextEvent)
|
|
||||||
module.exports.heatingStatus(heatingStatus)
|
|
||||||
},
|
},
|
||||||
heatingPageTwo: async (measuredRoomTemp, lastTimerSetPoint) => {
|
heatingPageTwo: async (measuredRoomTemp, lastTimerSetPoint) => {
|
||||||
module.exports.currentRoomTemp(measuredRoomTemp)
|
await module.exports.currentRoomTemp(measuredRoomTemp)
|
||||||
module.exports.lastSetTemp(lastTimerSetPoint)
|
await module.exports.lastSetTemp(lastTimerSetPoint)
|
||||||
},
|
},
|
||||||
waterPageOne: async (waterStatus, waterNextEvent) => {
|
waterPageOne: async (waterStatus, waterNextEvent) => {
|
||||||
module.exports.NextEvent(waterNextEvent)
|
await module.exports.NextEvent(waterNextEvent)
|
||||||
module.exports.waterStatus(waterStatus)
|
await module.exports.waterStatus(waterStatus)
|
||||||
|
},
|
||||||
|
piHolePage: async (domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked) => {
|
||||||
|
lcd.printLineSync(2, 'Queries=' + commaNumber(queriesToday))
|
||||||
|
lcd.printLineSync(3, 'Blocked=' + commaNumber(queriesBlockedToday) + ' (' + percentageBlocked.toFixed() + '%)')
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,15 +6,16 @@ const lcd = require('../libs/lcd')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
getStatus: () => {
|
getStatus: (page) => {
|
||||||
var rest_options = {
|
var rest_options = {
|
||||||
host: '192.168.4.5',
|
host: '192.168.4.5',
|
||||||
port: 2020,
|
port: 2020,
|
||||||
path: '/heating/status',
|
path: '/heating/status',
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
console.log('heating request')
|
let t = new Date().toUTCString()
|
||||||
var request = http.request(rest_options, function (response) {
|
console.log(t + ' heating request')
|
||||||
|
request = http.request(rest_options, function (response) {
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
||||||
// Handle data chunks
|
// Handle data chunks
|
||||||
@ -29,33 +30,34 @@ module.exports = {
|
|||||||
|
|
||||||
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
||||||
|
|
||||||
globalVars.waterNextEvent = time
|
globalVars.heatingNextEvent = time
|
||||||
|
|
||||||
let m = await common.time(data.nextScheduleEventUtcTime)
|
let m = await common.time(data.nextScheduleEventUtcTime)
|
||||||
|
|
||||||
if (globalVars.heatingOn === "" || globalVars.heatingOn === "error") {
|
if (globalVars.heatingOn === "" || globalVars.heatingOn === "error") {
|
||||||
if (heatingOn === 'true') {
|
if (heatingOn === 'true') {
|
||||||
globalVars.heatingOn = heatingOn
|
globalVars.heatingOn = heatingOn
|
||||||
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.heatingNextEvent)
|
||||||
led.set('red')
|
led.set('red')
|
||||||
} else {
|
} else {
|
||||||
globalVars.heatingOn = heatingOn
|
globalVars.heatingOn = heatingOn
|
||||||
lcd.heatingPageOne('Off', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
lcd.heatingPageOne('Off', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.heatingNextEvent)
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if (waterOn != globalVars.waterOn) {
|
|
||||||
if (heatingOn === 'true') {
|
if (heatingOn === 'true') {
|
||||||
globalVars.heatingOn = heatingOn
|
globalVars.heatingOn = heatingOn
|
||||||
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
lcd.heatingPageOne('On', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.heatingNextEvent)
|
||||||
led.set('red')
|
led.set('red')
|
||||||
} else {
|
} else {
|
||||||
|
if (page === 1) {
|
||||||
|
await lcd.heatingPageOne('Off', globalVars.heatingNextEvent)
|
||||||
|
} else {
|
||||||
|
await lcd.heatingPageTwo(data.measuredRoomTemp, data.lastTimerSetPoint)
|
||||||
|
}
|
||||||
globalVars.heatingOn = heatingOn
|
globalVars.heatingOn = heatingOn
|
||||||
// lcd.heatingPageOne('Off', data.measuredRoomTemp, data.lastTimerSetPoint, globalVars.waterNextEvent)
|
|
||||||
lcd.heatingPageTwo(data.measuredRoomTemp, data.lastTimerSetPoint)
|
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -8,31 +8,51 @@ var requireDir = require('require-dir');
|
|||||||
var modules = requireDir('../modules');
|
var modules = requireDir('../modules');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
home: () => {
|
home: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
clearInterval(globalVars.waterPolling);
|
||||||
screen.clearScreen()
|
clearInterval(globalVars.heatingPolling)
|
||||||
screen.heading('Main Menu')
|
clearInterval(globalVars.piHolePolling)
|
||||||
screen.time()
|
await screen.clearScreen()
|
||||||
setInterval(screen.time, 55000)
|
await screen.heading('Main Menu')
|
||||||
|
await screen.clearLine(2)
|
||||||
|
await screen.clearLine(3)
|
||||||
|
await screen.clearLine(4)
|
||||||
|
await screen.time()
|
||||||
},
|
},
|
||||||
water: () => {
|
water: async () => {
|
||||||
screen.clearScreen()
|
clearInterval(globalVars.waterPolling);
|
||||||
screen.heading('Hot Water')
|
clearInterval(globalVars.heatingPolling)
|
||||||
screen.time()
|
clearInterval(globalVars.piHolePolling)
|
||||||
setInterval(screen.time, 55000)
|
await screen.clearScreen()
|
||||||
modules.water.getStatus()
|
await screen.heading('Hot Water')
|
||||||
|
await screen.time()
|
||||||
|
await modules.water.getStatus()
|
||||||
globalVars.waterPolling = setInterval(() => {
|
globalVars.waterPolling = setInterval(() => {
|
||||||
modules.water.getStatus()
|
modules.water.getStatus()
|
||||||
}, 60000);
|
}, 60000);
|
||||||
},
|
},
|
||||||
heating: () => {
|
heating: async () => {
|
||||||
screen.clearScreen()
|
clearInterval(globalVars.waterPolling);
|
||||||
screen.heading('Heating')
|
clearInterval(globalVars.heatingPolling)
|
||||||
screen.time()
|
clearInterval(globalVars.piHolePolling)
|
||||||
setInterval(screen.time, 55000)
|
await screen.clearScreen()
|
||||||
modules.heating.getStatus()
|
await screen.heading('Heating')
|
||||||
globalVars.heatingPolling = setInterval(() => {
|
await screen.time()
|
||||||
modules.heating.getStatus()
|
await modules.heating.getStatus(globalVars.heatingPageS)
|
||||||
|
globalVars.heatingPolling = setInterval(async () => {
|
||||||
|
await modules.heating.getStatus(globalVars.heatingPageS)
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
},
|
||||||
|
piHole: async () => {
|
||||||
|
clearInterval(globalVars.waterPolling);
|
||||||
|
clearInterval(globalVars.heatingPolling)
|
||||||
|
clearInterval(globalVars.piHolePolling)
|
||||||
|
await screen.clearScreen()
|
||||||
|
await screen.heading('PiHole')
|
||||||
|
await screen.time()
|
||||||
|
await modules.pihole.getStatus()
|
||||||
|
globalVars.piHolePolling = setInterval(() => {
|
||||||
|
modules.pihole.getStatus()
|
||||||
|
}, 30000);
|
||||||
}
|
}
|
||||||
}
|
}
|
46
modules/pihole.js
Normal file
46
modules/pihole.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
const http = require('http')
|
||||||
|
const globalVars = require('../libs/globalVars')
|
||||||
|
const led = require('../libs/led')
|
||||||
|
const common = require('../libs/common')
|
||||||
|
const lcd = require('../libs/lcd')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
getStatus: () => {
|
||||||
|
var rest_options = {
|
||||||
|
host: '192.168.4.5',
|
||||||
|
port: 80,
|
||||||
|
path: '/admin/api.php',
|
||||||
|
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 domainsBeingBlocked = data.domains_being_blocked
|
||||||
|
let queriesToday = data.dns_queries_today
|
||||||
|
let queriesBlockedToday = data.ads_blocked_today
|
||||||
|
let percentageBlocked = data.ads_percentage_today
|
||||||
|
|
||||||
|
lcd.piHolePage(domainsBeingBlocked, queriesToday, queriesBlockedToday, percentageBlocked)
|
||||||
|
|
||||||
|
});
|
||||||
|
})
|
||||||
|
// Report errors
|
||||||
|
request.on('error', function (error) {
|
||||||
|
led.set('green')
|
||||||
|
lcd.heatingStatus('Error No Data')
|
||||||
|
globalVars.heatingOn = 'error'
|
||||||
|
});
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,8 @@ module.exports = {
|
|||||||
path: '/water/status',
|
path: '/water/status',
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
console.log('water request')
|
let t = new Date().toUTCString()
|
||||||
|
console.log(t + ' water request')
|
||||||
var request = http.request(rest_options, function (response) {
|
var request = http.request(rest_options, function (response) {
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
||||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -206,6 +206,11 @@
|
|||||||
"delayed-stream": "~1.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"comma-number": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/comma-number/-/comma-number-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-hrxY6UjA+tSUV5uZS2iOF8+/q7AACiq/zc9R6SO61MmOhrzNC0qXXh7g/jNYTm09fp6T40vQg15zkCmTJVA8Ww=="
|
||||||
|
},
|
||||||
"component-bind": {
|
"component-bind": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"comma-number": "^2.0.1",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"got": "^11.6.2",
|
"got": "^11.6.2",
|
||||||
"homeassistant": "^0.2.0",
|
"homeassistant": "^0.2.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user