bug fixes

This commit is contained in:
Skylar Grant 2023-01-06 17:04:46 -05:00
parent b7f9bacfa1
commit 283f963e38
7 changed files with 91 additions and 68 deletions

View File

@ -27,5 +27,11 @@
"prefix": "onpi", "prefix": "onpi",
"body": "if (process.env.ONPI == 'true') {\n\t$1\n} else {\n\t$2\n}$0", "body": "if (process.env.ONPI == 'true') {\n\t$1\n} else {\n\t$2\n}$0",
"description": "Run something only if the ONPI env var is set" "description": "Run something only if the ONPI env var is set"
},
"Error": {
"scope": "javascript",
"prefix": "err",
"body": "console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: $1`);\n$0",
"description": "Log an error to the console with timestamp"
} }
} }

View File

@ -1 +1 @@
{"debugMode":true,"status":{"igniter":0,"blower":0,"auger":0,"igniterFinished":false,"shutdown":0,"vacuum":0,"pof":0},"timestamps":{"procStart":1673037430589,"blowerOn":0,"blowerOff":0,"igniterOn":0,"igniterOff":0},"intervals":{"augerOn":"700","augerOff":"1300","igniterStart":5000,"blowerStop":5000},"web":{"port":8080,"ip":"0.0.0.0"}} {"debugMode":true,"status":{"igniter":0,"blower":0,"auger":0,"igniterFinished":false,"shutdown":0,"vacuum":0,"pof":0},"timestamps":{"procStart":1673042241248,"blowerOn":0,"blowerOff":0,"igniterOn":0,"igniterOff":0},"intervals":{"augerOn":"500","augerOff":"1500","pause":"5000","igniterStart":5000,"blowerStop":5000},"web":{"port":8080,"ip":"0.0.0.0"}}

View File

@ -17,25 +17,30 @@ const fs = require('fs');
const { time } = require('console'); const { time } = require('console');
const main = (gpio) => { const main = (gpio) => {
// If the auger is enabled functions.commands.refreshConfig().then(res => {
if (config.status.auger == 1) { // If the auger is enabled
// Run a cycle of the auger if (config.status.auger == 1) {
functions.auger.cycle(gpio).then(res => { // Run a cycle of the auger
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); functions.auger.cycle(gpio).then(res => {
// Recursion ecursion cursion ursion rsion sion ion on n if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
main(gpio); // Recursion ecursion cursion ursion rsion sion ion on n
}).catch(err => { main(gpio);
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); }).catch(err => {
}); if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`);
} else { });
// If the auger is disabled } else {
functions.commands.pause().then(res => { // If the auger is disabled
main(gpio); functions.commands.pause().then(res => {
}).catch(err => { main(gpio);
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); }).catch(err => {
main(gpio); if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`);
}); main(gpio);
} });
}
}).catch(rej => {
console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: Problem refreshing the config file.`);
main(gpio);
});
} }
// The functions we'll export to be used in other files // The functions we'll export to be used in other files
@ -144,20 +149,24 @@ const functions = {
}, },
refreshConfig(newSettings) { refreshConfig(newSettings) {
// When the reload button is pressed, the call to this function will contain new config values return new Promise((resolve, reject) => {
// { // When the reload button is pressed, the call to this function will contain new config values
// augerOff: 500, // {
// augerOn: 1500, // augerOff: 500,
// pause: 5000 // augerOn: 1500,
// } // pause: 5000
if (newSettings != undefined) { // }
config.intervals.augerOff = newSettings.augerOff; if (newSettings != undefined) {
config.intervals.augerOn = newSettings.augerOn; config.intervals.augerOff = newSettings.augerOff;
config.intervals.pause = newSettings.pause; config.intervals.augerOn = newSettings.augerOn;
} config.intervals.pause = newSettings.pause;
fs.writeFile('./config.json', JSON.stringify(config), (err) => { }
if (err) throw err; fs.writeFile('./config.json', JSON.stringify(config), (err) => {
}); if (err) reject(err);
resolve();
});
})
} }
}, },
// Sleeps for any given milliseconds // Sleeps for any given milliseconds

View File

@ -11,10 +11,21 @@ const express = require('express');
const app = express(); const app = express();
const http = require('http'); const http = require('http');
const server = http.createServer(app); const server = http.createServer(app);
const config = require('./config.json');
const fs = require('fs'); const fs = require('fs');
// const bodyParser = require('body-parser'); // const bodyParser = require('body-parser');
const fn = require('./functions.js').functions; var config;
var fn;
// First thing is to copy the template config to main config file
fs.readFile('./templates/config.json', (err, data) => {
fs.writeFile('./config.json', data, (err) => {
if (err) throw err;
console.log(`I: Config Template copied.`);
config = require('./config.json');
fn = require('./functions.js').functions;
server.listen(config.web.port, config.web.ip);
});
});
app.use(express.urlencoded()); app.use(express.urlencoded());
@ -45,12 +56,8 @@ app.post('/', (req, res) => {
fn.commands.refreshConfig({ fn.commands.refreshConfig({
augerOff: req.body.augerOff, augerOff: req.body.augerOff,
augerOn: req.body.augerOn, augerOn: req.body.augerOn,
pause: req.body.pause pause: req.body.pauseInt
}); });
} }
// res.send(200);
}); });
// console.log(req.body); });
});
server.listen(config.web.port, config.web.ip);

View File

@ -9,9 +9,15 @@ html, body {
#title { #title {
text-align: center; text-align: center;
font-size: 35px; font-size: 35px;
margin-top: 10px;
padding-bottom: 15px; padding-bottom: 15px;
} }
#title a {
text-decoration: none;
color: inherit;
}
#status { #status {
text-align: center; text-align: center;
} }
@ -71,7 +77,7 @@ html, body {
font-family: times; font-family: times;
font-size: 20px; font-size: 20px;
height: 35px; height: 35px;
width: 100px; width: 150px;
border-top-left-radius: 0px; border-top-left-radius: 0px;
border-bottom-left-radius: 0px; border-bottom-left-radius: 0px;
border-top-right-radius: 0px; border-top-right-radius: 0px;

View File

@ -32,30 +32,26 @@ function refreshData() {
const log = document.getElementById('log-area'); const log = document.getElementById('log-area');
log.contentWindow.location.reload(); log.contentWindow.location.reload();
sleep(100).then(() => { sleep(100).then(() => {
document.getElementById('log-area').contentWindow.scrollTo(0, 9999999); document.getElementById('log-area').contentWindow.scrollTo(0, 9999999999);
}); });
// Get the elements we need to update
const augerStatus = document.getElementById('auger-status'); const augerStatus = document.getElementById('auger-status');
// const augerOn = document.getElementById('auger-on'); const augerOn = document.getElementById('auger-on');
// const augerOff = document.getElementById('auger-off'); const augerOff = document.getElementById('auger-off');
const igniterStatus = document.getElementById('igniter-status'); const pauseInt = document.getElementById('pause-int');
const blowerStatus = document.getElementById('blower-status');
// const pauseInt = document.getElementById('pause-int'); // Get the config file
const vacuumStatus = document.getElementById('vacuum-status');
const pofStatus = document.getElementById('pof-status');
const config = readJSON('./config.json'); const config = readJSON('./config.json');
// console.log(config);
augerStatus.innerHTML = parseStatus(config.status.auger); augerStatus.innerHTML = parseStatus(config.status.auger);
// augerOn.innerHTML = parseStatus(config.intervals.augerOn); augerOn.value = config.intervals.augerOn;
// augerOff.innerHTML = parseStatus(config.intervals.augerOff); augerOff.value = config.intervals.augerOff;
igniterStatus.innerHTML = parseStatus(config.status.igniter); pauseInt.value = config.intervals.pause;
blowerStatus.innerHTML = parseStatus(config.status.blower);
// pauseInt.innerHTML = parseStatus(config.intervals.pause); // Run this again after 2 seconds
vacuumStatus.innerHTML = parseStatus(config.status.vacuum); sleep(5000).then(() => {
pofStatus.innerHTML = parseStatus(config.status.pof);
sleep(2000).then(() => {
refreshData(); refreshData();
}); });
}; };

View File

@ -6,14 +6,13 @@
</head> </head>
<body onload="refreshData()"> <body onload="refreshData()">
<%- include('trial.html') -%> <%- include('trial.html') -%>
<div id="title">Hestia Web Portal</div> <div id="title"><a href='./'>Hestia Web Portal</a></div>
<div id="status">Auger: <span id="auger-status"></span> | Igniter: <span id="igniter-status"></span> | Combustion Blower: <span id="blower-status"></span></div> <div id="status">Auger: <span id="auger-status"></span></div>
<div id="safeties">Vacuum: <span id="vacuum-status"></span> | Proof of Fire: <span id="pof-status"></span></div>
<div id="controls-container"> <div id="controls-container">
<form action="/" method="post"> <form action="/" method="post">
<!-- Start | Shutdown | Reload Settings --> <!-- Start | Shutdown | Reload Settings -->
<div class="button-container"> <div class="button-container">
<input class="button-unselected" type="submit" id="ignite" value="Start" name="start"><input class="button-unselected" type="submit" id="shutdown" value="Shutdown" name="shutdown"><input class="button-unselected" type="submit" id="reload" value="Reload" name="reload"><br> <input class="button-unselected" type="submit" id="ignite" value="Enable Auger" name="start"><input class="button-unselected" type="submit" id="shutdown" value="Disable Auger" name="shutdown"><input class="button-unselected" type="submit" id="reload" value="Reload" name="reload"><br>
</div> </div>
<!-- Set feed rates --> <!-- Set feed rates -->
<label for="augerOn">Auger On Interval: </label><input type="number" id="auger-on" name="augerOn" min="500" max="1000" step="100" value="<%= intervals.augerOn %>">ms<br> <label for="augerOn">Auger On Interval: </label><input type="number" id="auger-on" name="augerOn" min="500" max="1000" step="100" value="<%= intervals.augerOn %>">ms<br>
@ -21,17 +20,17 @@
<label for="pauseInt">App Pause Interval: </label><input type="number" id="pause-int" name="pauseInt" min="1000" max="600000" step="1000" value="<%= intervals.pause %>">ms<br> <label for="pauseInt">App Pause Interval: </label><input type="number" id="pause-int" name="pauseInt" min="1000" max="600000" step="1000" value="<%= intervals.pause %>">ms<br>
</form> </form>
</div> </div>
<div class="subheading"> <!-- <div class="subheading">
Pellet Feed Rate Pellet Feed Rate
</div> </div>
<div class="button-container"> <div class="button-container">
<button class="button-unselected" id="low-level">LOW</button><button class="button-unselected" id="med-level">MED</button><button class="button-unselected" id="hi-level">HI</button> <button class="button-unselected" id="low-level">LOW</button><button class="button-unselected" id="med-level">MED</button><button class="button-unselected" id="hi-level">HI</button>
</div> </div> -->
<div class="button-container"> <div class="button-container">
<img src="./dancing_jesus.gif"> <img src="./dancing_jesus.gif">
</div> </div>
<div id="log-container"> <div id="log-container">
<button id="refresh-log" onclick="refreshLog()">Refresh Log</button><br> <button id="refresh-log" onclick="refreshData()">Refresh Log</button><br>
<!-- <textarea id="log-area"></textarea> --> <!-- <textarea id="log-area"></textarea> -->
<iframe id="log-area" src="log.txt"></iframe> <iframe id="log-area" src="log.txt"></iframe>
</div> </div>