diff --git a/README.md b/README.md index 7cfe956..7acabdc 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,54 @@ For ease of adaption, connection, and prototyping I've decided to use Cat 5 ethe * Proof of Fire Switch OPEN after igniter shutoff. * Vacuum Switch OPEN after igniter start. 4. Test manipulation of feed rates. -5. Test shutdown sequence. \ No newline at end of file +5. Test shutdown sequence. + +# SQLite Database Tables + +## status +| Field | Type | Null | Key | Default | Extra | +| ----- | ---- | ---- | --- | ------- | ----- | +| id | int(10) | No | PRI | NULL | auto_increment | +| key | varchar(100) | No | | | +| value | varchar(1000) | No | | | + +| id | key | value | +| -- | --- | ----- | +0 | igniter | 0 +1 | blower | 0 +2 | auger | 0 +3 | igniter_finished | false +4 | shutdown_initiated | 0 +5 | vacuum | 0 +6 | proof_of_fire | 0 +7 | shutdown_next_cycle | 0 + +## timestamps +| Field | Type | Null | Key | Default | Extra | +| ----- | ---- | ---- | --- | ------- | ----- | +| id | int(10) | No | PRI | NULL | auto_increment | +| key | varchar(100) | No | | | +| value | varchar(1000) | No | | | + +| id | key | value | +| -- | --- | ----- | +0 | process_start | 0 +1 | blower_on | 0 +2 | blower_off | 0 +3 | igniter_on | 0 +4 | igniter_off | 0 + +## intervals +| Field | Type | Null | Key | Default | Extra | +| ----- | ---- | ---- | --- | ------- | ----- | +| id | int(10) | No | PRI | NULL | auto_increment | +| key | varchar(100) | No | | | +| value | varchar(1000) | No | | | + +| id | key | value | +| -- | --- | ----- | +0 | auger_on | 600 +1 | auger_off | 1400 +2 | pause | 5000 +3 | igniter_start | 420000 +4 | blower_stop | 600000 \ No newline at end of file diff --git a/data/strings.json b/data/strings.json new file mode 100644 index 0000000..91be3e7 --- /dev/null +++ b/data/strings.json @@ -0,0 +1,5 @@ +{ + "database": { + "createConfigTable": "" + } +} \ No newline at end of file diff --git a/functions.js b/functions.js index 6a757f2..048df1e 100644 --- a/functions.js +++ b/functions.js @@ -22,13 +22,13 @@ const main = (gpio) => { 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}`); + if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Recursion ecursion cursion ursion rsion sion ion on n functions.checkForQuit().then(n => { main(gpio); }); }).catch(err => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); + if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); }); } else { // If the auger is disabled @@ -37,7 +37,7 @@ const main = (gpio) => { main(gpio); }); }).catch(err => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); + if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: ${err}`); main(gpio); }); } @@ -92,19 +92,19 @@ const functions = { // Turn the auger on this.on(gpio).then((res) => { // Log action if in debug mode - // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + // if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Sleep for the time set in env variables functions.sleep(config.intervals.augerOn).then((res) => { // Log action if in debug mode - // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + // if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Turn the auger off this.off(gpio).then((res) => { // Log action if in debug mode - // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + // if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Sleep for the time set in env variables functions.sleep(config.intervals.augerOff).then((res) => { // Log action if in debug mode - // if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); + // if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${res}`); // Resolve the promise, letting the main script know the cycle is complete resolve(`Auger cycled (${config.intervals.augerOn}/${config.intervals.augerOff})`); }); @@ -130,10 +130,10 @@ const functions = { // Pauses the script for the time defined in env variables pause() { return new Promise((resolve) => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Pausing for ${config.intervals.pause}ms`); + if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Pausing for ${config.intervals.pause}ms`); functions.sleep(config.intervals.pause).then((res) => { - if (config.debugMode) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Pause finished.`); + if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Pause finished.`); resolve(); }); }); @@ -146,12 +146,12 @@ const functions = { // Delete the reload file fs.unlink('./reload', (err) => { if (err) throw err; - if (config.debugMode) console.log('Deleted reload file.'); + if (process.env.DEBUG) console.log('Deleted reload file.'); }); // Print out the new environment variables // This should be printed regardless of debug status, maybe prettied up TODO? console.log('Reloaded environment variables.'); - console.log(`ONTIME=${config.intervals.augerOn}\nOFFTIME=${config.intervals.augerOff}\nPAUSETIME=${config.intervals.pause}\nDEBUG=${config.debugMode}\nONPI=${process.env.ONPI}`); + console.log(`ONTIME=${config.intervals.augerOn}\nOFFTIME=${config.intervals.augerOff}\nPAUSETIME=${config.intervals.pause}\nDEBUG=${process.env.DEBUG}\nONPI=${process.env.ONPI}`); // Resolve the promise, letting the main script know we're done reloading the variables and the cycle can continue resolve(); }); @@ -192,7 +192,7 @@ const functions = { // Sleeps for any given milliseconds sleep(ms) { return new Promise((resolve) => { - // if (config.debugMode) console.log(`Sleeping for ${ms}ms`); + // if (process.env.DEBUG) console.log(`Sleeping for ${ms}ms`); // Function to be called when setTimeout finishes const finish = () => { // Resolve the promise @@ -224,14 +224,14 @@ const functions = { == == ONTIME=${config.intervals.augerOn} == == OFFTIME=${config.intervals.augerOff} == == PAUSETIME=${config.intervals.pause} -== == DEBUG=${config.debugMode} +== == DEBUG=${process.env.DEBUG} == == ONPI=${process.env.ONPI}`); // Set up GPIO 4 (pysical pin 7) as output, then call functions.auger.ready() if (process.env.ONPI == 'true') { // Init the Auger pin gpio.setup(augerPin, gpio.DIR_OUT, (err) => { if (err) reject(err); - if (config.debugMode) console.log('== Auger pin initialized.'); + if (process.env.DEBUG) console.log('== Auger pin initialized.'); // Resolve the promise now that all pins have been initialized resolve('== GPIO Initialized.'); }); diff --git a/modules/database.js b/modules/database.js new file mode 100644 index 0000000..7b76141 --- /dev/null +++ b/modules/database.js @@ -0,0 +1,23 @@ +// Get autocomplete + +module.exports = { + query(db) { + db.serialize(() => { + db.each(`SELECT PlaylistId as id, + Name as name + FROM playlists`, (err, row) => { + if (err) { + console.error(err.message); + } + console.log(row.id + "\t" + row.name); + }); + }); + + db.close((err) => { + if (err) { + console.error(err.message); + } + console.log('Close the database connection.'); + }); + } +}; \ No newline at end of file diff --git a/setupdb.js b/setupdb.js new file mode 100644 index 0000000..9efbde1 --- /dev/null +++ b/setupdb.js @@ -0,0 +1,7 @@ +const sqlite3 = require('sqlite3').verbose(); +// Connect to or create the database. +let db = new sqlite3.Database('./config.db', (err) => { + if (err) console.error("DB Connect: " + err); + console.log("Connected to database."); +}); + diff --git a/templates/config.json b/templates/config.json index 875e0b6..67e6643 100644 --- a/templates/config.json +++ b/templates/config.json @@ -1,5 +1,4 @@ { - "debugMode": true, "status": { "igniter": 0, "blower": 0, diff --git a/www/public/main.js b/www/public/main.js index a912347..da1453f 100644 --- a/www/public/main.js +++ b/www/public/main.js @@ -67,7 +67,7 @@ function refreshData() { feedRate.value = config.intervals.augerOn; // Run this again after 2 seconds - sleep(1000).then(() => { + sleep(5000).then(() => { refreshData(); }); }; \ No newline at end of file