From 5fa3d5bb9cd41fea6375f0eca2708997a906353f Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 21 Aug 2024 21:43:56 -0400 Subject: [PATCH] Comms working!! --- package.json | 3 ++- src/custom_modules/HestiaClasses.js | 3 ++- src/custom_modules/config.json | 7 +++++++ src/main.js | 5 ++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 98a2bad..d268e6f 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "author": "Skylar Grant", "license": "MIT", "dependencies": { - "dotenv": "^16.4.5" + "dotenv": "^16.4.5", + "mqtt": "^5.10.0" } } diff --git a/src/custom_modules/HestiaClasses.js b/src/custom_modules/HestiaClasses.js index b80919e..e1786c9 100644 --- a/src/custom_modules/HestiaClasses.js +++ b/src/custom_modules/HestiaClasses.js @@ -1,3 +1,5 @@ +const mqtt = require('mqtt'); + module.exports = { // State class State: class State { @@ -77,7 +79,6 @@ module.exports = { console.log(`Message received on topic ${topic}: ${msgStr}`); console.log(msgJson); state[msgJson.name].on = msgJson.on; - window.refreshState(window.document, state); }); } diff --git a/src/custom_modules/config.json b/src/custom_modules/config.json index 4828c6d..e7a7233 100644 --- a/src/custom_modules/config.json +++ b/src/custom_modules/config.json @@ -9,6 +9,13 @@ "auger": "hestia/status/auger" } }, + "states": { + "elements": [ + "igniter", + "exhaust", + "auger" + ] + }, "pins": [ { "key": "igniter", diff --git a/src/main.js b/src/main.js index 8630f6b..d4844ad 100644 --- a/src/main.js +++ b/src/main.js @@ -15,10 +15,9 @@ fn.gpio.debugInit(); setInterval(() => { for (const pin of config.pins) { if (pin.mode === 'IN') { - gpio.readPin(pin.board, (err, state) => { - if (err) throw err; + gpio.readPin(pin.board).then(state => { fn.log(`${pin.key}: ${state}`); - }); + }).catch(e => console.error(e)); } } }, 1000); \ No newline at end of file