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));
|
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) {
|
init(state, config) {
|
||||||
// Connect to the MQTT Broker
|
// 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, {
|
this.client = mqtt.connect(config.mqtt.address, {
|
||||||
username: 'hestia',
|
username: config.mqtt.username,
|
||||||
password: 'hestia'
|
password: config.mqtt.password
|
||||||
});
|
});
|
||||||
const { client } = this;
|
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';
|
import { Communicator, State } from './HestiaClasses.js';
|
||||||
let config;
|
|
||||||
const psState = new State();
|
const psState = new State();
|
||||||
const comms = new Communicator(psState);
|
const comms = new Communicator(psState);
|
||||||
|
const config = {
|
||||||
window.onload = async function() {
|
"mqtt": {
|
||||||
await fetch('/assets/config.json')
|
"address": "https://mqtt.3411.one",
|
||||||
.then(response => {
|
"username": "hestia",
|
||||||
if (!response.ok) {
|
"password": "hestia",
|
||||||
throw new Error('Network response was not ok');
|
"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);
|
psState.init(config);
|
||||||
comms.init(psState, config);
|
comms.init(psState, config);
|
||||||
refreshState(window.document, psState);
|
refreshState(window.document, psState);
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('There was a problem with the fetch operation:', error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function refreshState(doc, state) {
|
function refreshState(doc, state) {
|
||||||
@ -39,6 +46,7 @@ function refreshState(doc, state) {
|
|||||||
statusString = '';
|
statusString = '';
|
||||||
if (state.auger.on) statusString = "On"; else statusString = "Off";
|
if (state.auger.on) statusString = "On"; else statusString = "Off";
|
||||||
augerStatus.innerHTML = statusString;
|
augerStatus.innerHTML = statusString;
|
||||||
|
console.log('State refreshed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function power(element) {
|
function power(element) {
|
||||||
|
Loading…
Reference in New Issue
Block a user