<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js"></script>
<script>
const clientId = 'Browser_' + Math.random().toString(16).substr(2, 8);
client = new Paho.MQTT.Client("becker8.de", Number(63709), clientId);
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({
onSuccess: onConnect,
useSSL: true
});
function onConnect() {
console.log("Verbindung hergestellt");
client.subscribe("VLT");
client.subscribe("RLT");
client.subscribe("Hz");
client.subscribe("Pth");
client.subscribe("AT");
client.subscribe("RT");
client.subscribe("WW");
client.subscribe("GM");
client.subscribe("Nibe");
client.subscribe("COP");
client.subscribe("P");
client.subscribe("P1");
client.subscribe("P2");
client.subscribe("P3");
client.subscribe("U1");
client.subscribe("U2");
client.subscribe("U3");
client.subscribe("I1");
client.subscribe("I2");
client.subscribe("I3");
client.subscribe("PV");
client.subscribe("Verbrauch");
client.subscribe("Luft");
client.subscribe("Speicher");
client.subscribe("Speicher1");
client.subscribe("Speicher2");
client.subscribe("SoC1");
client.subscribe("SoC2");
client.subscribe("openwb");
client.subscribe("goe");
client.subscribe("STP8");
client.subscribe("STP6");
client.subscribe("SB3000");
client.subscribe("SW1");
client.subscribe("SW1%");
client.subscribe("SW2");
client.subscribe("SW2%");
client.subscribe("Gauben");
client.subscribe("Gauben%");
client.subscribe("Garage");
client.subscribe("Garage%");
client.subscribe("Nord");
client.subscribe("Nord%");
client.subscribe("PVT");
client.subscribe("PVM");
client.subscribe("PVJ");
client.subscribe("BezT");
client.subscribe("BezM");
client.subscribe("BezJ");
client.subscribe("EinT");
client.subscribe("EinM");
client.subscribe("EinJ");
client.subscribe("VerbT");
client.subscribe("VerbM");
client.subscribe("VerbJ");
}
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("Verbindung verloren:" + responseObject.errorMessage);
}
}
function onMessageArrived(message) {
//console.log("Beschreibung: " + message.destinationName);
//console.log("Nachricht: " + message.payloadString);
const topic = message.destinationName;
const destElem = document.getElementById(topic);
const value = message.payloadString;
const idList = ["P", "P1", "P2", "P3", "I1", "I2", "I3"];
if (idList.includes(topic)) {
if (value < 0) destElem.classList.add('minus');
else destElem.classList.remove('minus');
}
document.getElementById(topic).innerHTML = message.payloadString;
}
function displayTime() {
let currentDate = new Date();
let hours = currentDate.getHours();
let minutes = currentDate.getMinutes();
let seconds = currentDate.getSeconds();
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
let timeString = hours + ":" + minutes + ":" + seconds;
document.getElementById("zeit").innerHTML = timeString;
}
setInterval(displayTime, 1000);
setTimeout(function () {
const date = new Date();
document.getElementById("datum").textContent = new Intl.DateTimeFormat('de-DE', { dateStyle: 'full' }).format(date);
}, 1000);
</script>