From 595d46dda2a261a4236113bbbeb76d349aabc4a9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 21 Dec 2022 13:50:09 -0500 Subject: [PATCH] Ready for testing on psdev --- config.json | 32 +-------------------- functions.js | 10 +++++-- log.txt | 58 ++++++++++++++++++++++++++++++++++++++ main.js | 7 +++-- websvr.js | 10 ++++--- www/public/config.json | 1 + www/views/index.html | 63 ++++++++++++++++++++++++++++++++---------- 7 files changed, 127 insertions(+), 54 deletions(-) create mode 120000 www/public/config.json diff --git a/config.json b/config.json index 764b0a0..24f8a52 100644 --- a/config.json +++ b/config.json @@ -1,31 +1 @@ -{ - "debugMode": true, - "status": { - "igniter": 0, - "blower": 0, - "auger": 0, - "igniterFinished": false, - "seenFire": false, - "shutdown": 0, - "vacuum": 1, - "pof": 0 - }, - "timestamps": { - "procStart": 0, - "blowerOn": 0, - "blowerOff": 0, - "igniterOn": 0, - "igniterOff": 0 - }, - "intervals": { - "augerOn": 500, - "augerOff": 1500, - "pause": 3000, - "igniterStart": 30000, - "blowerStop": 10000 - }, - "web": { - "port": 8080, - "ip": "127.0.0.1" - } -} \ No newline at end of file +{"debugMode":true,"status":{"igniter":0,"blower":0,"auger":0,"igniterFinished":true,"seenFire":false,"shutdown":0,"vacuum":1,"pof":1},"timestamps":{"procStart":1671648471606,"blowerOn":1671648232716,"blowerOff":1671648326617,"igniterOn":1671648232717,"igniterOff":1671648263542},"intervals":{"augerOn":500,"augerOff":1500,"pause":3000,"igniterStart":30000,"blowerStop":10000},"web":{"port":8080,"ip":"127.0.0.1"}} \ No newline at end of file diff --git a/functions.js b/functions.js index cce97ae..dfbfee6 100644 --- a/functions.js +++ b/functions.js @@ -246,7 +246,8 @@ const functions = { functions.power.blower.off(gpio).then(res => { // Since the blower shutting off is the last step in the shutdown, we can quit. // TODO eventually we don't want to ever quit the program, so it can be restarted remotely - functions.commands.quit(); + // functions.commands.quit(); + config.status.shutdown = 0; }); } else { return "A shutdown has already been initiated and the blower is preventing shutdown."; @@ -254,6 +255,11 @@ const functions = { } }, + writeConfig() { + fs.writeFile('./config.json', JSON.stringify(config), (err) => { + if (err) throw err; + }); + } }, tests: { vacuum(gpio) { @@ -341,7 +347,7 @@ const functions = { // } // TODO I think this needs to be moved elsewhere, it doesn't finish resolving before the resolve call on line 354 is called (344+10=354) functions.power.igniter.off(gpio).then(res => { - statusMsg += res; + if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); }); } else if ((Date.now() > config.timestamps.igniterOff) && (config.status.igniter == 0)) { statusMsg += `The igniter was turned off at ${new Date(config.timestamps.igniterOff).toISOString()}.`; diff --git a/log.txt b/log.txt index e69de29..3bbc883 100644 --- a/log.txt +++ b/log.txt @@ -0,0 +1,58 @@ +[0] I: Not running on a Raspberry Pi. +== Lennox Winslow PS40 +== Pellet Stove Control Panel +== Author: Skylar Grant +== Version: v0.2.1 +== +== Startup Time: 2022-12-21T18:47:51.607Z +== +== Environment variables: +== == ONTIME=500 +== == OFFTIME=1500 +== == PAUSETIME=3000 +== == DEBUG=true +== == ONPI=false +[0.008] I: == GPIO Not Available +[0.008] I: Pausing for 3000ms +[3.012] I: Pausing for 3000ms +[6.014] I: Pausing for 3000ms +[9.016] I: Pausing for 3000ms +[12.018] I: Pausing for 3000ms +[15.019] I: Pausing for 3000ms +[18.02] I: Pausing for 3000ms +[21.021] I: Pausing for 3000ms +[24.022] I: Pausing for 3000ms +[27.024] I: Pausing for 3000ms +[30.027] I: Pausing for 3000ms +[33.029] I: Pausing for 3000ms +[36.031] I: Pausing for 3000ms +[39.032] I: Pausing for 3000ms +[42.032] I: Pausing for 3000ms +[45.034] I: Pausing for 3000ms +[48.035] I: Pausing for 3000ms +[51.037] I: Pausing for 3000ms +[54.039] I: Pausing for 3000ms +[57.04] I: Pausing for 3000ms +[60.041] I: Pausing for 3000ms +[63.043] I: Pausing for 3000ms +[66.044] I: Pausing for 3000ms +[69.046] I: Pausing for 3000ms +[72.048] I: Pausing for 3000ms +[75.049] I: Pausing for 3000ms +[78.05] I: Pausing for 3000ms +[81.052] I: Pausing for 3000ms +[84.054] I: Pausing for 3000ms +[87.055] I: Pausing for 3000ms +[90.057] I: Pausing for 3000ms +[93.059] I: Pausing for 3000ms +[96.061] I: Pausing for 3000ms +[99.063] I: Pausing for 3000ms +[102.064] I: Pausing for 3000ms +[105.065] I: Pausing for 3000ms +[108.065] I: Pausing for 3000ms +[111.067] I: Pausing for 3000ms +[114.069] I: Pausing for 3000ms +[117.071] I: Pausing for 3000ms +[120.071] I: Pausing for 3000ms +[123.073] I: Pausing for 3000ms +[126.075] I: Pausing for 3000ms diff --git a/main.js b/main.js index ee4a698..30d3b04 100644 --- a/main.js +++ b/main.js @@ -99,14 +99,14 @@ async function main(fn, gpio) { if (config.status.auger == 1) { fn.auger.cycle(gpio).then((res) => { // Log the auger cycle results if in debug mode. - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Run the status check function statusCheck(fn, gpio); // Rerun this function once the cycle is complete // main(fn, gpio); }); } else { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger Status: ${config.status.auger}`); + // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger Status: ${config.status.auger}`); fn.commands.pause().then(res => { statusCheck(fn, gpio); @@ -124,6 +124,7 @@ async function main(fn, gpio) { } function statusCheck(fn, gpio) { + fn.commands.writeConfig(); if (config.status.shutdown == 1) { console.log(fn.commands.shutdown(gpio) || 'Shutting down...'); main(fn, gpio); @@ -152,7 +153,7 @@ function statusCheck(fn, gpio) { console.log(fn.commands.shutdown(gpio)); main(fn, gpio); } else { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Vacuum and Proof of Fire OK.`); + // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Vacuum and Proof of Fire OK.`); main(fn, gpio); } }); diff --git a/websvr.js b/websvr.js index cb79578..8da5ec6 100644 --- a/websvr.js +++ b/websvr.js @@ -15,7 +15,7 @@ const config = require('./config.json'); const fs = require('fs'); // const bodyParser = require('body-parser'); const core = require('./main.js'); -const fn = require('./functions.js'); +const fn = require('./functions.js').functions; const gpio = require('rpi-gpio'); app.use(express.urlencoded()); @@ -31,7 +31,6 @@ app.get('/', (req, res) => { res.render('index', JSON.parse(data)); // res.send(200); }); - console.log(req); }); app.post('/', (req, res) => { @@ -39,11 +38,14 @@ app.post('/', (req, res) => { // console.log(JSON.parse(data)); res.render('index', JSON.parse(data)); if (req.body.start != undefined) { - core.main(fn, gpio); + fn.commands.ignite(gpio); + } + if (req.body.shutdown != undefined) { + fn.commands.shutdown(gpio); } // res.send(200); }); - console.log(req.body); + // console.log(req.body); }); server.listen(config.web.port, config.web.ip); \ No newline at end of file diff --git a/www/public/config.json b/www/public/config.json new file mode 120000 index 0000000..1fdca95 --- /dev/null +++ b/www/public/config.json @@ -0,0 +1 @@ +/Users/voidf1sh/pscontrolpanel/config.json \ No newline at end of file diff --git a/www/views/index.html b/www/views/index.html index 690fdd3..78a2304 100644 --- a/www/views/index.html +++ b/www/views/index.html @@ -4,11 +4,11 @@ Pellet Stove Web Portal - + <%- include('trial.html') -%>
Pellet Stove Web Portal
-
Auger: <%= status.auger %> | Igniter: <%= status.igniter %> | Combustion Blower: <%= status.blower %>
-
Vacuum: <%= status.vacuum %> | Proof of Fire: <%= status.pof %>
+
Auger: | Igniter: | Combustion Blower:
+
Vacuum: | Proof of Fire:
@@ -16,23 +16,58 @@
- ms
- ms
- ms
+ ms
+ ms
+ ms
- +
+