working time cleanup

This commit is contained in:
Karl Hudgell 2020-09-14 12:27:18 +01:00
parent db5597d702
commit cc06dfb78c
6 changed files with 58 additions and 68 deletions

4
app.js
View File

@ -9,8 +9,8 @@ const lcd = require('./libs/lcd')
async function main() { async function main() {
lcd.clearScreen() lcd.clearScreen()
await lcd.intro() await lcd.intro()
lcd.time() setInterval(lcd.time, 55000)
hotwater.setInterval setInterval(hotwater.getStatus, 5000)
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');

View File

@ -1,10 +1,10 @@
const moment = require('moment'); // require
module.exports = { module.exports = {
time: () => { time: () => {
try { try {
t = moment().format('HH:MM'); var time = new Date();
return t currentTime = ("0" + time.getHours()).slice(-2) + ":" +
("0" + time.getMinutes()).slice(-2)
return currentTime
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }

View File

@ -29,19 +29,10 @@ module.exports = {
lcd.printLineSync(2, title) lcd.printLineSync(2, title)
}, },
time: async () => { time: async () => {
// set interval
var tid = setInterval(mycode, 60000);
async function mycode() {
lcd.setCursorSync(15, 0); lcd.setCursorSync(15, 0);
let f let f
f = await clock.time() f = await clock.time()
lcd.printSync(f) lcd.printSync(f)
}
function abortTimer() { // to be called when you want to stop the timer
clearInterval(tid);
}
}, },
heatingStatus: async (input) => { heatingStatus: async (input) => {
lcd.setCursorSync(0, 3); lcd.setCursorSync(0, 3);

View File

@ -1,16 +1,12 @@
const http = require('http') const http = require('http')
const { Gpio } = require('onoff');
const globalVars = require('../libs/globalVars') const globalVars = require('../libs/globalVars')
const led = require('../libs/led') const led = require('../libs/led')
const redLED = new Gpio('4', 'out');
const blueLED = new Gpio('27', 'out')
const greenLED = new Gpio('22', 'out')
const lcd = require('../libs/lcd') const lcd = require('../libs/lcd')
setInterval(function () { module.exports = {
getStatus: () => {
var rest_options = { var rest_options = {
host: '192.168.4.5', host: '192.168.4.5',
port: 2020, port: 2020,
@ -65,8 +61,5 @@ setInterval(function () {
}); });
request.end(); request.end();
}, 5000); }
module.exports = {
setInterval
} }

View File

@ -12,7 +12,6 @@
"fs": "0.0.1-security", "fs": "0.0.1-security",
"got": "^11.6.2", "got": "^11.6.2",
"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",

13
test.js
View File

@ -1,5 +1,12 @@
const moment = require('moment'); // require // const moment = require('moment'); // require
t = moment().format('HH:MM:ss'); // t = moment().format('HH:MM:ss');
console.log(t) // console.log(t)
var time = new Date();
currentTime = ("0" + time.getHours()).slice(-2) + ":" +
("0" + time.getMinutes()).slice(-2)
console.log(currentTime)