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 hotwater = require('./modules/hotwater')
|
||||
const hotwater = require('./modules/water')
|
||||
const common = require('./libs/common')
|
||||
const globalVars = require('./libs/globalVars')
|
||||
const led = require('./libs/led')
|
||||
@ -9,8 +9,8 @@ const menu = require('./modules/mainMenu')
|
||||
async function main() {
|
||||
lcd.clearScreen()
|
||||
await lcd.intro()
|
||||
menu.home()
|
||||
|
||||
menu.water()
|
||||
|
||||
const heatingSwitch = new Gpio('17', '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
|
||||
let i = 0
|
||||
appSwitch.watch(async (err, value) => {
|
||||
@ -36,14 +36,18 @@ async function main() {
|
||||
}
|
||||
if (value === 1) {
|
||||
switch (arr[i]) {
|
||||
case 'hotwater':
|
||||
menu.hotWater()
|
||||
case 'water':
|
||||
await menu.water()
|
||||
break;
|
||||
case 'main-menu':
|
||||
globalVars.waterPolling = 0
|
||||
setInterval(hotwater.getStatus, globalVars.waterPolling)
|
||||
case 'mainMenu':
|
||||
clearInterval(globalVars.heatingPolling)
|
||||
led.set('off')
|
||||
menu.home()
|
||||
await menu.home()
|
||||
break;
|
||||
case 'heating':
|
||||
clearInterval(globalVars.waterPolling)
|
||||
led.set('off')
|
||||
await menu.heating()
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -1,4 +1,5 @@
|
||||
const got = require('got');
|
||||
const moment = require('moment');
|
||||
|
||||
module.exports = {
|
||||
request: async (input) => {
|
||||
@ -19,21 +20,26 @@ module.exports = {
|
||||
await new Promise(resolve => setTimeout(resolve, time));
|
||||
},
|
||||
nextEvent: async (time) => {
|
||||
|
||||
time = time.match(/.{11}$/gm)
|
||||
time = time[0].toLowerCase()
|
||||
|
||||
var hours = parseInt(time.substr(0, 2));
|
||||
if (time.indexOf('am') != -1 && hours == 12) {
|
||||
time = time.replace('12', '0');
|
||||
if (time === 'Thursday, January 1st, 1970 12:13:00 AM') {
|
||||
return 'No Timer Set'
|
||||
} else {
|
||||
time = time.match(/.{11}$/gm)
|
||||
time = time[0].toLowerCase()
|
||||
var hours = parseInt(time.substr(0, 2));
|
||||
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 = time.replace(/(am|pm)/, '');
|
||||
time = time.replace(/ /g,'')
|
||||
return time.substring(0, time.length - 3);
|
||||
},
|
||||
time: async (nextEvent) => {
|
||||
let currentDate = moment(new Date(new Date().toUTCString()))
|
||||
nextEvent = moment(nextEvent, "dddd, MMMM Do, YYYY LTS")
|
||||
return currentDate.isAfter(nextEvent);
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
class globalVariables {
|
||||
waterOn = "";
|
||||
waterNextEvent = "";
|
||||
waterPolling = 0
|
||||
waterPolling = "";
|
||||
heatingNextEvent = "";
|
||||
heatingPolling = "";
|
||||
}
|
||||
|
||||
module.exports = new globalVariables();
|
21
libs/lcd.js
21
libs/lcd.js
@ -19,20 +19,19 @@ module.exports = {
|
||||
intro: async () => {
|
||||
lcd.clearSync();
|
||||
lcd.printLineSync(1, 'MiGenie Status')
|
||||
lcd.printLineSync(2, ' By Karl')
|
||||
lcd.setCursorSync(13, 2);
|
||||
lcd.printSync('By Karl')
|
||||
await common.pause(3000)
|
||||
lcd.clearSync();
|
||||
},
|
||||
heading: async (title) => {
|
||||
lcd.setCursorSync(0, 0);
|
||||
lcd.printSync(title)
|
||||
module.exports.time()
|
||||
},
|
||||
time: async () => {
|
||||
console.log('get time')
|
||||
lcd.setCursorSync(15, 0);
|
||||
let f
|
||||
f = await clock.time()
|
||||
lcd.printSync(f)
|
||||
lcd.printSync(await clock.time())
|
||||
},
|
||||
waterStatus: async (input) => {
|
||||
lcd.printLineSync(2, 'Water=')
|
||||
@ -41,7 +40,14 @@ module.exports = {
|
||||
lcd.setCursorSync(6, 2);
|
||||
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") {
|
||||
lcd.printLineSync(3, 'Switch Off=')
|
||||
lcd.setCursorSync(11, 3);
|
||||
@ -56,4 +62,7 @@ module.exports = {
|
||||
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 led = require('../libs/led')
|
||||
const common = require('../libs/common')
|
||||
const modules = require('../modules/hotwater')
|
||||
|
||||
const screen = require('../libs/lcd')
|
||||
|
||||
var requireDir = require('require-dir');
|
||||
var modules = requireDir('../modules');
|
||||
|
||||
module.exports = {
|
||||
home: () => {
|
||||
clearInterval(globalVars.waterPolling);
|
||||
screen.clearScreen()
|
||||
screen.heading('Main Menu')
|
||||
screen.time()
|
||||
setInterval(screen.time, 55000)
|
||||
},
|
||||
hotWater: () => {
|
||||
globalVars.waterPolling = 30000
|
||||
water: () => {
|
||||
screen.clearScreen()
|
||||
screen.heading('Hot Water')
|
||||
screen.time()
|
||||
setInterval(screen.time, 55000)
|
||||
modules.getStatus()
|
||||
modules.water.getStatus()
|
||||
globalVars.waterPolling = setInterval(() => {
|
||||
modules.getStatus()
|
||||
}, 30000);
|
||||
modules.water.getStatus()
|
||||
}, 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 led = require('../libs/led')
|
||||
const common = require('../libs/common')
|
||||
|
||||
const lcd = require('../libs/lcd')
|
||||
|
||||
module.exports = {
|
||||
@ -14,7 +13,7 @@ module.exports = {
|
||||
path: '/water/status',
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
console.log('water request')
|
||||
var request = http.request(rest_options, function (response) {
|
||||
var content = "";
|
||||
|
||||
@ -32,32 +31,34 @@ module.exports = {
|
||||
|
||||
globalVars.waterNextEvent = time
|
||||
|
||||
let m = await common.time(data.nextScheduleEventUtcTime)
|
||||
|
||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||
if (waterOn === 'true') {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Heating')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
lcd.NextEvent(globalVars.waterNextEvent)
|
||||
led.set('red')
|
||||
} else {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
lcd.NextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
} else {
|
||||
if (waterOn != globalVars.waterOn) {
|
||||
if (waterOn === 'true') {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Heating')
|
||||
led.set('red')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
} else {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
lcd.waterNextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
// if (waterOn != globalVars.waterOn) {
|
||||
if (waterOn === 'true') {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Heating')
|
||||
led.set('red')
|
||||
lcd.NextEvent(globalVars.waterNextEvent)
|
||||
} else {
|
||||
globalVars.waterOn = waterOn
|
||||
lcd.waterStatus('Not Heating')
|
||||
led.set('blue')
|
||||
lcd.NextEvent(globalVars.waterNextEvent)
|
||||
}
|
||||
// }
|
||||
}
|
||||
});
|
||||
});
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -726,6 +726,11 @@
|
||||
"sleep": "^6.1.0"
|
||||
}
|
||||
},
|
||||
"readline": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
|
||||
"integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw="
|
||||
},
|
||||
"request": {
|
||||
"version": "2.88.2",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
|
||||
@ -753,6 +758,11 @@
|
||||
"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": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
@ -881,6 +891,11 @@
|
||||
"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": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
|
||||
|
@ -13,10 +13,14 @@
|
||||
"got": "^11.6.2",
|
||||
"homeassistant": "^0.2.0",
|
||||
"http": "0.0.1-security",
|
||||
"moment": "^2.28.0",
|
||||
"onoff": "^6.0.0",
|
||||
"pigpio": "^3.2.3",
|
||||
"raspberrypi-liquid-crystal": "^1.15.0",
|
||||
"readline": "^1.3.0",
|
||||
"require-dir": "^1.2.0",
|
||||
"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