From 1de8ba78a7209fb19cc9d37fa1cf85619d4be8b2 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 20 Dec 2022 21:12:22 -0500 Subject: [PATCH] web server sugma --- main.js | 10 +++++++--- package-lock.json | 1 + package.json | 1 + websvr.js | 17 +++++++++++++++-- www/views/index.html | 4 ++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index 7f3cf25..ee4a698 100644 --- a/main.js +++ b/main.js @@ -3,8 +3,10 @@ * v0.2 * * TODO: - * Add logic for other sensors - * More documentation? + * Update documentation + * Move some of these functions to the functions file so they can be called from the web server + * Or move the web server here and remove the first init + * Or just remove the first init call and start the init elsewhere after main() is called */ // Custom functions module to keep main script clean @@ -156,4 +158,6 @@ function statusCheck(fn, gpio) { }); } }); -} \ No newline at end of file +} + +module.exports = main; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 60ad689..f14bb1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "pscontrolpanel", "version": "0.2.1", "dependencies": { + "body-parser": "^1.20.1", "dotenv": "^16.0.3", "ejs": "^3.1.8", "express": "^4.18.2", diff --git a/package.json b/package.json index 3f49663..f305c30 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "requires": true, "packages": {}, "dependencies": { + "body-parser": "^1.20.1", "dotenv": "^16.0.3", "ejs": "^3.1.8", "express": "^4.18.2", diff --git a/websvr.js b/websvr.js index 21a84b7..cb79578 100644 --- a/websvr.js +++ b/websvr.js @@ -13,6 +13,12 @@ const http = require('http'); const server = http.createServer(app); 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 gpio = require('rpi-gpio'); + +app.use(express.urlencoded()); app.use(express.static(__dirname + '/www/public')); app.set('views', __dirname + '/www/views'); @@ -29,8 +35,15 @@ app.get('/', (req, res) => { }); app.post('/', (req, res) => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${req.body}`); - // oop + fs.readFile(__dirname + '/config.json', (err, data) => { + // console.log(JSON.parse(data)); + res.render('index', JSON.parse(data)); + if (req.body.start != undefined) { + core.main(fn, gpio); + } + // res.send(200); + }); + console.log(req.body); }); server.listen(config.web.port, config.web.ip); \ No newline at end of file diff --git a/www/views/index.html b/www/views/index.html index 8234edf..690fdd3 100644 --- a/www/views/index.html +++ b/www/views/index.html @@ -10,10 +10,10 @@
Auger: <%= status.auger %> | Igniter: <%= status.igniter %> | Combustion Blower: <%= status.blower %>
Vacuum: <%= status.vacuum %> | Proof of Fire: <%= status.pof %>
-
+
-
+
ms