reworked and working heating
This commit is contained in:
parent
29989f1afc
commit
ba3e106a1b
24
app.js
24
app.js
@ -1,5 +1,5 @@
|
|||||||
const { Gpio } = require('onoff');
|
const { Gpio } = require('onoff');
|
||||||
const hotwater = require('./modules/hotwater')
|
const hotwater = require('./modules/water')
|
||||||
const common = require('./libs/common')
|
const common = require('./libs/common')
|
||||||
const globalVars = require('./libs/globalVars')
|
const globalVars = require('./libs/globalVars')
|
||||||
const led = require('./libs/led')
|
const led = require('./libs/led')
|
||||||
@ -9,8 +9,8 @@ const menu = require('./modules/mainMenu')
|
|||||||
async function main() {
|
async function main() {
|
||||||
lcd.clearScreen()
|
lcd.clearScreen()
|
||||||
await lcd.intro()
|
await lcd.intro()
|
||||||
menu.home()
|
menu.water()
|
||||||
|
|
||||||
const heatingSwitch = new Gpio('17', 'in', 'both');
|
const heatingSwitch = new Gpio('17', 'in', 'both');
|
||||||
const appSwitch = new Gpio('23', 'in', 'both');
|
const appSwitch = new Gpio('23', 'in', 'both');
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const arr = ['hotwater', 'main-menu']
|
const arr = ['water', 'heating', 'mainMenu']
|
||||||
arrLength = arr.length
|
arrLength = arr.length
|
||||||
let i = 0
|
let i = 0
|
||||||
appSwitch.watch(async (err, value) => {
|
appSwitch.watch(async (err, value) => {
|
||||||
@ -36,14 +36,18 @@ async function main() {
|
|||||||
}
|
}
|
||||||
if (value === 1) {
|
if (value === 1) {
|
||||||
switch (arr[i]) {
|
switch (arr[i]) {
|
||||||
case 'hotwater':
|
case 'water':
|
||||||
menu.hotWater()
|
await menu.water()
|
||||||
break;
|
break;
|
||||||
case 'main-menu':
|
case 'mainMenu':
|
||||||
globalVars.waterPolling = 0
|
clearInterval(globalVars.heatingPolling)
|
||||||
setInterval(hotwater.getStatus, globalVars.waterPolling)
|
|
||||||
led.set('off')
|
led.set('off')
|
||||||
menu.home()
|
await menu.home()
|
||||||
|
break;
|
||||||
|
case 'heating':
|
||||||
|
clearInterval(globalVars.waterPolling)
|
||||||
|
led.set('off')
|
||||||
|
await menu.heating()
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const got = require('got');
|
const got = require('got');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
request: async (input) => {
|
request: async (input) => {
|
||||||
@ -19,21 +20,26 @@ module.exports = {
|
|||||||
await new Promise(resolve => setTimeout(resolve, time));
|
await new Promise(resolve => setTimeout(resolve, time));
|
||||||
},
|
},
|
||||||
nextEvent: async (time) => {
|
nextEvent: async (time) => {
|
||||||
|
if (time === 'Thursday, January 1st, 1970 12:13:00 AM') {
|
||||||
time = time.match(/.{11}$/gm)
|
return 'No Timer Set'
|
||||||
time = time[0].toLowerCase()
|
} else {
|
||||||
|
time = time.match(/.{11}$/gm)
|
||||||
var hours = parseInt(time.substr(0, 2));
|
time = time[0].toLowerCase()
|
||||||
if (time.indexOf('am') != -1 && hours == 12) {
|
var hours = parseInt(time.substr(0, 2));
|
||||||
time = time.replace('12', '0');
|
if (time.indexOf('am') != -1 && hours == 12) {
|
||||||
|
time = time.replace('12', '0');
|
||||||
|
}
|
||||||
|
if (time.indexOf('pm') != -1 && hours < 12) {
|
||||||
|
time = time.replace(hours, (hours + 12));
|
||||||
|
}
|
||||||
|
time = time.replace(/(am|pm)/, '');
|
||||||
|
time = time.replace(/ /g, '')
|
||||||
|
return time.substring(0, time.length - 3);
|
||||||
}
|
}
|
||||||
if (time.indexOf('pm') != -1 && hours < 12) {
|
},
|
||||||
time = time.replace(hours, (hours + 12));
|
time: async (nextEvent) => {
|
||||||
}
|
let currentDate = moment(new Date(new Date().toUTCString()))
|
||||||
|
nextEvent = moment(nextEvent, "dddd, MMMM Do, YYYY LTS")
|
||||||
|
return currentDate.isAfter(nextEvent);
|
||||||
time = time.replace(/(am|pm)/, '');
|
|
||||||
time = time.replace(/ /g,'')
|
|
||||||
return time.substring(0, time.length - 3);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,9 @@
|
|||||||
class globalVariables {
|
class globalVariables {
|
||||||
waterOn = "";
|
waterOn = "";
|
||||||
waterNextEvent = "";
|
waterNextEvent = "";
|
||||||
waterPolling = 0
|
waterPolling = "";
|
||||||
|
heatingNextEvent = "";
|
||||||
|
heatingPolling = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new globalVariables();
|
module.exports = new globalVariables();
|
21
libs/lcd.js
21
libs/lcd.js
@ -19,20 +19,19 @@ module.exports = {
|
|||||||
intro: async () => {
|
intro: async () => {
|
||||||
lcd.clearSync();
|
lcd.clearSync();
|
||||||
lcd.printLineSync(1, 'MiGenie Status')
|
lcd.printLineSync(1, 'MiGenie Status')
|
||||||
lcd.printLineSync(2, ' By Karl')
|
lcd.setCursorSync(13, 2);
|
||||||
|
lcd.printSync('By Karl')
|
||||||
await common.pause(3000)
|
await common.pause(3000)
|
||||||
lcd.clearSync();
|
lcd.clearSync();
|
||||||
},
|
},
|
||||||
heading: async (title) => {
|
heading: async (title) => {
|
||||||
lcd.setCursorSync(0, 0);
|
lcd.setCursorSync(0, 0);
|
||||||
lcd.printSync(title)
|
lcd.printSync(title)
|
||||||
module.exports.time()
|
|
||||||
},
|
},
|
||||||
time: async () => {
|
time: async () => {
|
||||||
|
console.log('get time')
|
||||||
lcd.setCursorSync(15, 0);
|
lcd.setCursorSync(15, 0);
|
||||||
let f
|
lcd.printSync(await clock.time())
|
||||||
f = await clock.time()
|
|
||||||
lcd.printSync(f)
|
|
||||||
},
|
},
|
||||||
waterStatus: async (input) => {
|
waterStatus: async (input) => {
|
||||||
lcd.printLineSync(2, 'Water=')
|
lcd.printLineSync(2, 'Water=')
|
||||||
@ -41,7 +40,14 @@ module.exports = {
|
|||||||
lcd.setCursorSync(6, 2);
|
lcd.setCursorSync(6, 2);
|
||||||
lcd.printSync(input)
|
lcd.printSync(input)
|
||||||
},
|
},
|
||||||
waterNextEvent: async (input) => {
|
waterStatus: async (input) => {
|
||||||
|
lcd.printLineSync(2, 'Heating=')
|
||||||
|
lcd.setCursorSync(8, 2);
|
||||||
|
lcd.printSync(' ')
|
||||||
|
lcd.setCursorSync(8, 2);
|
||||||
|
lcd.printSync(input)
|
||||||
|
},
|
||||||
|
NextEvent: async (input) => {
|
||||||
if (globalVars.waterOn === "true") {
|
if (globalVars.waterOn === "true") {
|
||||||
lcd.printLineSync(3, 'Switch Off=')
|
lcd.printLineSync(3, 'Switch Off=')
|
||||||
lcd.setCursorSync(11, 3);
|
lcd.setCursorSync(11, 3);
|
||||||
@ -56,4 +62,7 @@ module.exports = {
|
|||||||
lcd.printSync(input)
|
lcd.printSync(input)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
degrees: async () => {
|
||||||
|
let icon = '°'
|
||||||
|
}
|
||||||
}
|
}
|
77
modules/heating.js
Normal file
77
modules/heating.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
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: 2020,
|
||||||
|
path: '/heating/status',
|
||||||
|
method: 'GET'
|
||||||
|
};
|
||||||
|
console.log('heating 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 heatingOn = data.heatingOn
|
||||||
|
let currentRoomTemp = data.measuredRoomTemp
|
||||||
|
let currentSetPoint = data.currentSetpoint
|
||||||
|
|
||||||
|
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
||||||
|
|
||||||
|
globalVars.waterNextEvent = time
|
||||||
|
|
||||||
|
let m = await common.time(data.nextScheduleEventUtcTime)
|
||||||
|
|
||||||
|
if (globalVars.heatingOn === "" || globalVars.heatingOn === "error") {
|
||||||
|
if (heatingOn === 'true') {
|
||||||
|
globalVars.heatingOn = heatingOn
|
||||||
|
lcd.heatingStatus('On')
|
||||||
|
lcd.NextEvent(globalVars.heatingNextEvent)
|
||||||
|
led.set('red')
|
||||||
|
} else {
|
||||||
|
globalVars.waterOn = waterOn
|
||||||
|
lcd.heatingStatus('Off')
|
||||||
|
led.set('blue')
|
||||||
|
lcd.NextEvent(globalVars.heatingNextEvent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if (waterOn != globalVars.waterOn) {
|
||||||
|
if (heatingOn === 'true') {
|
||||||
|
globalVars.heatingOn = heatingOn
|
||||||
|
lcd.heatingStatus('On')
|
||||||
|
led.set('red')
|
||||||
|
lcd.NextEvent(globalVars.heatingNextEvent)
|
||||||
|
} else {
|
||||||
|
globalVars.heatingOn = heatingOn
|
||||||
|
lcd.heatingStatus('Off')
|
||||||
|
led.set('blue')
|
||||||
|
lcd.NextEvent(globalVars.waterNextEvent)
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Report errors
|
||||||
|
request.on('error', function (error) {
|
||||||
|
led.set('green')
|
||||||
|
lcd.heatingStatus('Error No Data')
|
||||||
|
globalVars.heatingOn = 'error'
|
||||||
|
});
|
||||||
|
|
||||||
|
request.end();
|
||||||
|
}
|
||||||
|
}
|
@ -2,25 +2,37 @@ const http = require('http')
|
|||||||
const globalVars = require('../libs/globalVars')
|
const globalVars = require('../libs/globalVars')
|
||||||
const led = require('../libs/led')
|
const led = require('../libs/led')
|
||||||
const common = require('../libs/common')
|
const common = require('../libs/common')
|
||||||
const modules = require('../modules/hotwater')
|
|
||||||
|
|
||||||
const screen = require('../libs/lcd')
|
const screen = require('../libs/lcd')
|
||||||
|
|
||||||
|
var requireDir = require('require-dir');
|
||||||
|
var modules = requireDir('../modules');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
home: () => {
|
home: () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
clearInterval(globalVars.waterPolling);
|
||||||
screen.clearScreen()
|
screen.clearScreen()
|
||||||
screen.heading('Main Menu')
|
screen.heading('Main Menu')
|
||||||
|
screen.time()
|
||||||
|
setInterval(screen.time, 55000)
|
||||||
},
|
},
|
||||||
hotWater: () => {
|
water: () => {
|
||||||
globalVars.waterPolling = 30000
|
|
||||||
screen.clearScreen()
|
screen.clearScreen()
|
||||||
screen.heading('Hot Water')
|
screen.heading('Hot Water')
|
||||||
|
screen.time()
|
||||||
setInterval(screen.time, 55000)
|
setInterval(screen.time, 55000)
|
||||||
modules.getStatus()
|
modules.water.getStatus()
|
||||||
globalVars.waterPolling = setInterval(() => {
|
globalVars.waterPolling = setInterval(() => {
|
||||||
modules.getStatus()
|
modules.water.getStatus()
|
||||||
}, 30000);
|
}, 60000);
|
||||||
|
},
|
||||||
|
heating: () => {
|
||||||
|
screen.clearScreen()
|
||||||
|
screen.heading('Heating')
|
||||||
|
screen.time()
|
||||||
|
setInterval(screen.time, 55000)
|
||||||
|
modules.heating.getStatus()
|
||||||
|
globalVars.heatingPolling = setInterval(() => {
|
||||||
|
modules.heating.getStatus()
|
||||||
|
}, 60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,6 @@ const http = require('http')
|
|||||||
const globalVars = require('../libs/globalVars')
|
const globalVars = require('../libs/globalVars')
|
||||||
const led = require('../libs/led')
|
const led = require('../libs/led')
|
||||||
const common = require('../libs/common')
|
const common = require('../libs/common')
|
||||||
|
|
||||||
const lcd = require('../libs/lcd')
|
const lcd = require('../libs/lcd')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -14,7 +13,7 @@ module.exports = {
|
|||||||
path: '/water/status',
|
path: '/water/status',
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
};
|
};
|
||||||
|
console.log('water request')
|
||||||
var request = http.request(rest_options, function (response) {
|
var request = http.request(rest_options, function (response) {
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
||||||
@ -32,32 +31,34 @@ module.exports = {
|
|||||||
|
|
||||||
globalVars.waterNextEvent = time
|
globalVars.waterNextEvent = time
|
||||||
|
|
||||||
|
let m = await common.time(data.nextScheduleEventUtcTime)
|
||||||
|
|
||||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||||
if (waterOn === 'true') {
|
if (waterOn === 'true') {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterOn
|
||||||
lcd.waterStatus('Heating')
|
lcd.waterStatus('Heating')
|
||||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
lcd.NextEvent(globalVars.waterNextEvent)
|
||||||
led.set('red')
|
led.set('red')
|
||||||
} else {
|
} else {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterOn
|
||||||
lcd.waterStatus('Not Heating')
|
lcd.waterStatus('Not Heating')
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
lcd.NextEvent(globalVars.waterNextEvent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (waterOn != globalVars.waterOn) {
|
// if (waterOn != globalVars.waterOn) {
|
||||||
if (waterOn === 'true') {
|
if (waterOn === 'true') {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterOn
|
||||||
lcd.waterStatus('Heating')
|
lcd.waterStatus('Heating')
|
||||||
led.set('red')
|
led.set('red')
|
||||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
lcd.NextEvent(globalVars.waterNextEvent)
|
||||||
} else {
|
} else {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterOn
|
||||||
lcd.waterStatus('Not Heating')
|
lcd.waterStatus('Not Heating')
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
lcd.NextEvent(globalVars.waterNextEvent)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -726,6 +726,11 @@
|
|||||||
"sleep": "^6.1.0"
|
"sleep": "^6.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"readline": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
|
||||||
|
"integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw="
|
||||||
|
},
|
||||||
"request": {
|
"request": {
|
||||||
"version": "2.88.2",
|
"version": "2.88.2",
|
||||||
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
|
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
|
||||||
@ -753,6 +758,11 @@
|
|||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"require-dir": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/require-dir/-/require-dir-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-LY85DTSu+heYgDqq/mK+7zFHWkttVNRXC9NKcKGyuGLdlsfbjEPrIEYdCVrx6hqnJb+xSu3Lzaoo8VnmOhhjNA=="
|
||||||
|
},
|
||||||
"require-directory": {
|
"require-directory": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
@ -881,6 +891,11 @@
|
|||||||
"tweetnacl": "~0.14.0"
|
"tweetnacl": "~0.14.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"time-loop": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/time-loop/-/time-loop-2.0.3.tgz",
|
||||||
|
"integrity": "sha1-AI0jivfcj/tyt9iO3C3fOK0cJpI="
|
||||||
|
},
|
||||||
"to-array": {
|
"to-array": {
|
||||||
"version": "0.1.4",
|
"version": "0.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
|
||||||
|
@ -13,10 +13,14 @@
|
|||||||
"got": "^11.6.2",
|
"got": "^11.6.2",
|
||||||
"homeassistant": "^0.2.0",
|
"homeassistant": "^0.2.0",
|
||||||
"http": "0.0.1-security",
|
"http": "0.0.1-security",
|
||||||
|
"moment": "^2.28.0",
|
||||||
"onoff": "^6.0.0",
|
"onoff": "^6.0.0",
|
||||||
"pigpio": "^3.2.3",
|
"pigpio": "^3.2.3",
|
||||||
"raspberrypi-liquid-crystal": "^1.15.0",
|
"raspberrypi-liquid-crystal": "^1.15.0",
|
||||||
|
"readline": "^1.3.0",
|
||||||
|
"require-dir": "^1.2.0",
|
||||||
"require-directory": "^2.1.1",
|
"require-directory": "^2.1.1",
|
||||||
"socket.io": "^2.3.0"
|
"socket.io": "^2.3.0",
|
||||||
|
"time-loop": "^2.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user