Minor changes

This commit is contained in:
Skylar Grant 2024-11-30 16:52:10 -05:00
parent a59dd3fe6f
commit 5e20cfff6e
4 changed files with 24 additions and 16 deletions

View File

@ -88,11 +88,11 @@ module.exports = {
return this; return this;
} }
init(state, config) { init(state, host, port, config) {
// Connect to the MQTT Broker // Connect to the MQTT Broker
this.emit('announcement', `Attempting MQTT connection to broker: ${config.mqtt.address}`); this.emit('announcement', `Attempting MQTT connection to broker: ${host}:${port}`);
this.client = mqtt.connect(config.mqtt.address, { this.client = mqtt.connect(host, {
port: config.mqtt.port, port: port,
}); });
const { client } = this; const { client } = this;
@ -144,6 +144,19 @@ module.exports = {
this.emit('announcement', `Unknown topic: ${topic}`); this.emit('announcement', `Unknown topic: ${topic}`);
} }
}); });
// Other MQTT client events [pingreq, pingresp, disconnect]
client.on('pingreq', () => {
this.emit('announcement', 'Ping request received from MQTT broker');
});
client.on('pingresp', () => {
this.emit('announcement', 'Ping response sent to MQTT broker');
});
client.on('disconnect', () => {
this.emit('announcement', 'Disconnected from MQTT broker');
});
} }
// Publish a message to the MQTT Broker // Publish a message to the MQTT Broker

View File

@ -1,7 +1,5 @@
{ {
"mqtt": { "mqtt": {
"address": "wss://192.168.0.12",
"port": 9001,
"topics": { "topics": {
"igniter": "hestia/status/igniter", "igniter": "hestia/status/igniter",
"exhaust": "hestia/status/exhaust", "exhaust": "hestia/status/exhaust",

View File

@ -1,13 +1,7 @@
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 } = config;
const gpio = require('./VoidGPIO.js'); const gpio = require('./VoidGPIO.js');
process.pinMap = new Map();
for (const pin of pins) {
process.pinMap.set(pin.key, pin);
}
module.exports = { module.exports = {
log(message, level) { log(message, level) {

View File

@ -11,7 +11,6 @@ const { State, Communicator } = require('./custom_modules/HestiaClasses.js');
/***************************************************************************************/ /***************************************************************************************/
// Variables // Variables
/***************************************************************************************/ /***************************************************************************************/
process.debug = true;
process.pinMap = new Map(); process.pinMap = new Map();
for (const pin of config.pins) { for (const pin of config.pins) {
process.pinMap.set(pin.key, pin); process.pinMap.set(pin.key, pin);
@ -22,8 +21,6 @@ for (const pin of config.pins) {
/***************************************************************************************/ /***************************************************************************************/
process.psState = new State(config); process.psState = new State(config);
process.comlink = new Communicator(process.psState); process.comlink = new Communicator(process.psState);
process.comlink.init(process.psState, config);
fn.gpio.init(process.comlink, process.psState);
/***************************************************************************************/ /***************************************************************************************/
// Loops // Loops
@ -80,4 +77,10 @@ process.comlink.on('announcement', msg => {
process.psState.on('announcement', msg => { process.psState.on('announcement', msg => {
fn.log(`State: ${msg}`, 'INFO'); fn.log(`State: ${msg}`, 'INFO');
}); });
/***************************************************************************************/
// Call Things
/***************************************************************************************/
process.comlink.init(process.psState, process.env.MQTT_HOST, process.env.MQTT_PORT, config);
fn.gpio.init(process.comlink, process.psState);