Added some debug logging, moved config to main file
This commit is contained in:
parent
358136a6ef
commit
97c2343993
@ -16,7 +16,9 @@ export class State {
|
||||
communicator.send(sub.topic, JSON.stringify(this));
|
||||
}
|
||||
};
|
||||
console.log(`${sub.name} initialized.`)
|
||||
});
|
||||
console.log(`State initialized.`)
|
||||
}
|
||||
};
|
||||
|
||||
@ -28,9 +30,10 @@ export class Communicator {
|
||||
|
||||
init(state, config) {
|
||||
// Connect to the MQTT Broker
|
||||
console.log(`Attempting MQTT connection to broker: ${config.mqtt.address}, with username: ${config.mqtt.username}`);
|
||||
this.client = mqtt.connect(config.mqtt.address, {
|
||||
username: 'hestia',
|
||||
password: 'hestia'
|
||||
username: config.mqtt.username,
|
||||
password: config.mqtt.password
|
||||
});
|
||||
const { client } = this;
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"mqtt": {
|
||||
"address": "https://mqtt.3411.one",
|
||||
"subscriptions": [
|
||||
{
|
||||
"name": "igniter",
|
||||
"topic": "hestia/status/igniter"
|
||||
},
|
||||
{
|
||||
"name": "exhaust",
|
||||
"topic": "hestia/status/exhaust"
|
||||
},
|
||||
{
|
||||
"name": "auger",
|
||||
"topic": "hestia/status/auger"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,25 +1,32 @@
|
||||
import { Communicator, State } from './HestiaClasses.js';
|
||||
let config;
|
||||
const psState = new State();
|
||||
const comms = new Communicator(psState);
|
||||
|
||||
window.onload = async function() {
|
||||
await fetch('/assets/config.json')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
const config = {
|
||||
"mqtt": {
|
||||
"address": "https://mqtt.3411.one",
|
||||
"username": "hestia",
|
||||
"password": "hestia",
|
||||
"subscriptions": [
|
||||
{
|
||||
"name": "igniter",
|
||||
"topic": "hestia/status/igniter"
|
||||
},
|
||||
{
|
||||
"name": "exhaust",
|
||||
"topic": "hestia/status/exhaust"
|
||||
},
|
||||
{
|
||||
"name": "auger",
|
||||
"topic": "hestia/status/auger"
|
||||
}
|
||||
return response.json(); // Parse the JSON data from the response
|
||||
})
|
||||
.then(data => {
|
||||
config = data;
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
psState.init(config);
|
||||
comms.init(psState, config);
|
||||
refreshState(window.document, psState);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('There was a problem with the fetch operation:', error);
|
||||
});
|
||||
};
|
||||
|
||||
function refreshState(doc, state) {
|
||||
@ -39,6 +46,7 @@ function refreshState(doc, state) {
|
||||
statusString = '';
|
||||
if (state.auger.on) statusString = "On"; else statusString = "Off";
|
||||
augerStatus.innerHTML = statusString;
|
||||
console.log('State refreshed.');
|
||||
}
|
||||
|
||||
function power(element) {
|
||||
|
Loading…
Reference in New Issue
Block a user