working time cleanup
This commit is contained in:
parent
db5597d702
commit
cc06dfb78c
4
app.js
4
app.js
@ -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');
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -1,47 +1,32 @@
|
|||||||
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 = {
|
||||||
|
|
||||||
var rest_options = {
|
getStatus: () => {
|
||||||
host: '192.168.4.5',
|
var rest_options = {
|
||||||
port: 2020,
|
host: '192.168.4.5',
|
||||||
path: '/water/status',
|
port: 2020,
|
||||||
method: 'GET'
|
path: '/water/status',
|
||||||
};
|
method: 'GET'
|
||||||
|
};
|
||||||
|
|
||||||
var request = http.request(rest_options, function (response) {
|
var request = http.request(rest_options, function (response) {
|
||||||
var content = "";
|
var content = "";
|
||||||
|
|
||||||
// Handle data chunks
|
// Handle data chunks
|
||||||
response.on('data', function (chunk) {
|
response.on('data', function (chunk) {
|
||||||
content += chunk;
|
content += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Once we're done streaming the response, parse it as json.
|
// Once we're done streaming the response, parse it as json.
|
||||||
response.on('end', function () {
|
response.on('end', function () {
|
||||||
var data = JSON.parse(content);
|
var data = JSON.parse(content);
|
||||||
let waterOn = data.waterOn
|
let waterOn = data.waterOn
|
||||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||||
if (waterOn === 'true') {
|
|
||||||
lcd.heatingStatus('Heating')
|
|
||||||
led.set('red')
|
|
||||||
globalVars.waterOn = waterOn
|
|
||||||
} else {
|
|
||||||
lcd.heatingStatus('Not Heating')
|
|
||||||
led.set('blue')
|
|
||||||
globalVars.waterOn = waterOn
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (waterOn != globalVars.waterOn) {
|
|
||||||
if (waterOn === 'true') {
|
if (waterOn === 'true') {
|
||||||
lcd.heatingStatus('Heating')
|
lcd.heatingStatus('Heating')
|
||||||
led.set('red')
|
led.set('red')
|
||||||
@ -51,22 +36,30 @@ setInterval(function () {
|
|||||||
led.set('blue')
|
led.set('blue')
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterOn
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (waterOn != globalVars.waterOn) {
|
||||||
|
if (waterOn === 'true') {
|
||||||
|
lcd.heatingStatus('Heating')
|
||||||
|
led.set('red')
|
||||||
|
globalVars.waterOn = waterOn
|
||||||
|
} else {
|
||||||
|
lcd.heatingStatus('Not Heating')
|
||||||
|
led.set('blue')
|
||||||
|
globalVars.waterOn = waterOn
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Report errors
|
// Report errors
|
||||||
request.on('error', function (error) {
|
request.on('error', function (error) {
|
||||||
lcd.heatingStatus('Error')
|
lcd.heatingStatus('Error')
|
||||||
led.set('green')
|
led.set('green')
|
||||||
lcd.heatingStatus('Error No Data')
|
lcd.heatingStatus('Error No Data')
|
||||||
globalVars.waterOn = 'error'
|
globalVars.waterOn = 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
request.end();
|
request.end();
|
||||||
}, 5000);
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
setInterval
|
|
||||||
}
|
}
|
@ -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
13
test.js
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user