Compare commits

..

No commits in common. "9e543989b8ba90762cf556e5a07652bdcce00360" and "459008d372b998ded12a37367a3e881115c3af6d" have entirely different histories.

4 changed files with 36 additions and 73 deletions

View File

@ -1,8 +1,7 @@
# In Progress # In Progress
1. ~~Strip to bones~~ 1. ~~Strip to bones~~
2. Better commenting 2. Better commenting
3. Add startup and shutdown logic (implemented, not tested) 2. Add startup and shutdown logic (start half implemented, not tested)
4. Connect to MQTT
# Done # Done
1. GPIO Interface 1. GPIO Interface

View File

@ -1,13 +1,20 @@
{ {
"mqtt": { "mqtt": {
"address": "wss://mqtt.3411.one", "address": "wd://broker-url:port",
"username": "hestia", "subscriptions": [
"password": "hestia", {
"topics": { "name": "igniter",
"igniter": "hestia/status/igniter", "topic": "hestia/status/igniter"
"exhaust": "hestia/status/exhaust", },
"auger": "hestia/status/auger" {
"name": "exhaust",
"topic": "hestia/status/exhaust"
},
{
"name": "auger",
"topic": "hestia/status/auger"
} }
]
}, },
"pins": [ "pins": [
{ {

View File

@ -1,7 +1,7 @@
const dotenv = require('dotenv').config(); const dotenv = require('dotenv').config();
const debug = process.env.DEBUG === "TRUE"; const debug = process.env.DEBUG === "TRUE";
const config = require('./config.json'); const config = require('./config.json');
const { pins } = config; const { pins } = require('./config.json');
const gpio = require('./VoidGPIO.js'); const gpio = require('./VoidGPIO.js');
const pinMap = new Map(); const pinMap = new Map();
@ -59,9 +59,10 @@ module.exports = {
}); });
break; break;
case 'IN': case 'IN':
gpio.readPin(pin.board).then(state => { gpio.readPin(pin.board, (err, state) => {
if (err) throw err;
module.exports.log(`${pin.key} state: ${state}`); module.exports.log(`${pin.key} state: ${state}`);
}).catch(e => console.error(e)); });
default: default:
break; break;
} }
@ -74,77 +75,41 @@ module.exports = {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
// TODO: Check pin states? // TODO: Check pin states?
// Set pins to default states // T_DONE: Set pins to default states
module.exports.gpio.setDefaults().then(changes => { module.exports.gpio.setDefaults().then(changes => {
module.exports.log(changes); module.exports.log(changes);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Power on igniter // T_DONE: Power on igniter
gpio.setPin(pinMap.igniter.board, 1).then(async () => { gpio.setPin(pinMap.igniter.board, 1).then(async () => {
// Wait for igniter preheat // T_DONE: Wait for igniter preheat
await module.exports.sleep(config.power.start.exhaustDelay); await module.exports.sleep(config.power.start.exhaustDelay);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Start exhaust // T_DONE: Start exhaust
gpio.setPin(pinMap.exhaust.board, 1).then(async () => { gpio.setPin(pinMap.exhaust.board, 1).then(async () => {
// Finish igniter preheat // T_DONE: Finish igniter preheat
await module.exports.sleep(config.power.start.augerDelay); await module.exports.sleep(config.power.start.augerDelay);
}).catch(e => console.error(e)); }).catch(e => console.error(e));
// Check for vacuum // Check for vacuum
gpio.readPin(pinMap.vacuum.board).then(state => {
if (state === '0') {
// Power off exhaust
gpio.setPin(pinMap.exhaust.board, 0).then(() => {
// Report vacuum failure
reject(new Error('Vacuum failure.'));
return;
}).catch(e => console.error(e));
} else {
// Start auger // Start auger
gpio.setPin(pinMap.auger.board, 1).then(async () => {
// Wait for fire // Wait for fire
await module.exports.sleep(config.power.start.fireCheckDelay);
// Check for fire
// Power off igniter // Power off igniter
gpio.setPin(pinMap.igniter.board, 0).then(() => {
// Check for fire on pof
gpio.readPin(pinMap.pof.board).then(state => {
if (state === '0') {
// Power off auger
gpio.setPin(pinMap.auger.board, 0).then(() => {
// Report failed ignition
reject(new Error('Failed ignition.'));
}).catch(e => console.error(e));
} else {
// Power off auger
gpio.setPin(pinMap.auger.board, 0).then(() => {
// Report successful ignition // Report successful ignition
resolve('Successful ignition.');
}).catch(e => console.error(e));
}
}).catch(e => console.error(e));
}).catch(e => console.error(e));
}).catch(e => console.error(e));
}
}).catch(e => console.error(e));
}); });
} }
}, },
stop: { stop: {
init() { init() {
return new Promise(async (resolve, reject) => {
// Power off auger
gpio.setPin(pinMap.auger.board, 0).then(async () => {
// Wait for exhaust shutdown delay
await module.exports.sleep(config.power.stop.exhaustDelay);
// Power off exhaust
gpio.setPin(pinMap.exhaust.board, 0).then(() => {
// Report successful shutdown
resolve('Successful shutdown.');
}).catch(e => console.error(e));
}).catch(e => console.error(e));
});
} }
} }
} }

View File

@ -2,16 +2,8 @@
const gpio = require('./custom_modules/VoidGPIO.js'); const gpio = require('./custom_modules/VoidGPIO.js');
const { pins } = require('./custom_modules/config.json'); const { pins } = require('./custom_modules/config.json');
const fn = require('./custom_modules/functions.js'); const fn = require('./custom_modules/functions.js');
const { State, Communicator } = require('./custom_modules/HestiaClasses.js');
const psState = new State(config);
const comms = new Communicator(psState);
comms.init(psState, config);
fn.gpio.debugInit(); fn.gpio.debugInit();
// Sensor detection loop
setInterval(() => { setInterval(() => {
for (const pin of pins) { for (const pin of pins) {
if (pin.mode === 'IN') { if (pin.mode === 'IN') {