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",
"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"
},
"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 main = (gpio) => {
// If the auger is enabled
if (config.status.auger == 1) {
// Run a cycle of the auger
functions.auger.cycle(gpio).then(res => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
// Recursion ecursion cursion ursion rsion sion ion on n
main(gpio);
}).catch(err => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`);
});
} else {
// If the auger is disabled
functions.commands.pause().then(res => {
main(gpio);
}).catch(err => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`);
main(gpio);
});
}
functions.commands.refreshConfig().then(res => {
// If the auger is enabled
if (config.status.auger == 1) {
// Run a cycle of the auger
functions.auger.cycle(gpio).then(res => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`);
// Recursion ecursion cursion ursion rsion sion ion on n
main(gpio);
}).catch(err => {
if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`);
});
} else {
// If the auger is disabled
functions.commands.pause().then(res => {
main(gpio);
}).catch(err => {
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
@ -144,20 +149,24 @@ const functions = {
},
refreshConfig(newSettings) {
// When the reload button is pressed, the call to this function will contain new config values
// {
// augerOff: 500,
// augerOn: 1500,
// pause: 5000
// }
if (newSettings != undefined) {
config.intervals.augerOff = newSettings.augerOff;
config.intervals.augerOn = newSettings.augerOn;
config.intervals.pause = newSettings.pause;
}
fs.writeFile('./config.json', JSON.stringify(config), (err) => {
if (err) throw err;
});
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,
// pause: 5000
// }
if (newSettings != undefined) {
config.intervals.augerOff = newSettings.augerOff;
config.intervals.augerOn = newSettings.augerOn;
config.intervals.pause = newSettings.pause;
}
fs.writeFile('./config.json', JSON.stringify(config), (err) => {
if (err) reject(err);
resolve();
});
})
}
},
// Sleeps for any given milliseconds

View File

@ -11,10 +11,21 @@ const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const config = require('./config.json');
const fs = require('fs');
// 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());
@ -45,12 +56,8 @@ app.post('/', (req, res) => {
fn.commands.refreshConfig({
augerOff: req.body.augerOff,
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 {
text-align: center;
font-size: 35px;
margin-top: 10px;
padding-bottom: 15px;
}
#title a {
text-decoration: none;
color: inherit;
}
#status {
text-align: center;
}
@ -71,7 +77,7 @@ html, body {
font-family: times;
font-size: 20px;
height: 35px;
width: 100px;
width: 150px;
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
border-top-right-radius: 0px;

View File

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

View File

@ -6,14 +6,13 @@
</head>
<body onload="refreshData()">
<%- include('trial.html') -%>
<div id="title">Hestia Web Portal</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="safeties">Vacuum: <span id="vacuum-status"></span> | Proof of Fire: <span id="pof-status"></span></div>
<div id="title"><a href='./'>Hestia Web Portal</a></div>
<div id="status">Auger: <span id="auger-status"></span></div>
<div id="controls-container">
<form action="/" method="post">
<!-- Start | Shutdown | Reload Settings -->
<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>
<!-- 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>
@ -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>
</form>
</div>
<div class="subheading">
<!-- <div class="subheading">
Pellet Feed Rate
</div>
<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>
</div>
</div> -->
<div class="button-container">
<img src="./dancing_jesus.gif">
</div>
<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> -->
<iframe id="log-area" src="log.txt"></iframe>
</div>