fetch("../device").then( function(text) { return text.text() } ).then( function(text2) { element = document.getElementById("deviceheader"); element.innerText = text2} ) function getTime() { fetch("../time"). then( function(text) { if(!text.ok) { throw text }; return text.text() }).then( function(text2) { timeobj = JSON.parse(text2); element = document.getElementById("rtc"); element.innerText = timeobj.mday + "." + (timeobj.month +1) + "." + (timeobj.year + 1900) + " " + addZero(timeobj.hour) + ":" + addZero(timeobj.minutes) + ":" + addZero(timeobj.seconds) }).catch(function(error) { console.log("failed to fetch the time") }) } function addZero(num) { if (num < 10) { return "0" + num; } return num; } function getSystemTime() { date = new Date(); element = document.getElementById("local"); element.innerText = date.getDate() + "." + (date.getMonth() + 1) + "." + (date.getYear() + 1900) + " " + addZero(date.getHours()) + ":" + addZero(date.getMinutes()) + ":" + addZero(date.getSeconds()); } function getAlarm() { fetch("../wkalrm").then(function(text) { if(!text.ok) { throw text }; return text.text() }).then( function(text2) { alarmdiv = document.getElementById("alarm"); alarmdiv.style.visibility="visible"; alarmtime=document.getElementById("alarm-time"); alarmobj=JSON.parse(text2); alarmtime.innerText = alarmobj.mday + "." + (alarmobj.month +1) + "." + (alarmobj.year + 1900) + " " + addZero(alarmobj.hour) + ":" + addZero(alarmobj.minutes) + ":" + addZero(alarmobj.seconds); alarm_status=document.getElementById("alarm-status"); alarm_status.innerText="Status: "; alarm_status.innerText += alarmobj.enabled ? " aktiviert" : " deaktiviert"; alarm_status.innerText += "\nAusgelöst: "; alarm_status.innerText += alarmobj.pending ? " ja" : " nein"}).catch( function(error) { console.log("alarm access failed") }) } getSystemTime() getNVRAM() getAlarm() getTime() function getNVRAM() { fetch("../nvmem").then(function(text) { if(!text.ok) { throw text }; return text.text() }).then( function(text2) { nvobj = JSON.parse(text2); element = document.getElementById("nvram-text"); element.innerText = nvobj.content; element2 = document.getElementById("nvram"); element2.style.visibility="visible"; }).catch( function(error) { console.log("error while reading nvram") }) } function submitNvRAM() { nvobj = {}; element = document.getElementById("nvram-text"); nvobj.content = element.value; fetch("../nvmem", {method: "POST", body: JSON.stringify(nvobj)}).then( function(x) {alert("NVRAM erfolgreich geschrieben"); getNVRAM()}).catch( function(error) { alert("Fehler beim Schreiben in den NVRAM") }) } function changeAlarm() { element = document.getElementById("alarm-time"); if (element.childElementCount === 0) { fetch("../wkalrm").then(function(text) {return text.text() }).then( function(text2) { element.innerText = ""; textarea = document.createElement("textarea"); textarea.id = "alarmtext"; textarea.rows=1; textarea.cols=20; alarmobj = JSON.parse(text2); textarea.innerText = alarmobj.mday + "." + (alarmobj.month +1) + "." + (alarmobj.year + 1900) + " " + addZero(alarmobj.hour) + ":" + addZero(alarmobj.minutes) + ":" + addZero(alarmobj.seconds); element.appendChild(textarea)}) } else { textelement = document.getElementById("alarmtext"); alstring = textelement.value.split(" "); date = alstring[0].split("."); time = alstring[1].split(":"); alobj = { "seconds": parseInt(time[2]), "minutes": parseInt(time[1]), "hour": parseInt(time[0]), "mday": parseInt(date[0]), "month": parseInt(date[1]) -1, "year": parseInt(date[2]) -1900, "wday": 0, "enabled": 1, "pending": 0 } fetch("../wkalrm", {method: "POST", body: JSON.stringify(alobj)}).then(function() {textelement.remove(); getAlarm();}).then(function(x) {alert("Alarmzeitpunkt erfolgreich geändert!")}).catch(function(y) {alert("Fehler beim Schreiben des Alarms!")}) } } function changeRTC() { element = document.getElementById("rtc"); if (element.childElementCount === 0) { fetch("../time").then(function(text) {return text.text() }).then( function(text2) { element.innerText = ""; textarea = document.createElement("textarea"); textarea.id = "rtctext"; textarea.rows=1; textarea.cols=20; timeobj = JSON.parse(text2); textarea.innerText = timeobj.mday + "." + (timeobj.month +1) + "." + (timeobj.year + 1900) + " " + addZero(timeobj.hour) + ":" + addZero(timeobj.minutes) + ":" + addZero(timeobj.seconds); element.appendChild(textarea);}) } else { textelement = document.getElementById("rtctext"); alstring = textelement.value.split(" "); date = alstring[0].split("."); time = alstring[1].split(":"); tobj = { "seconds": parseInt(time[2]), "minutes": parseInt(time[1]), "hour": parseInt(time[0]), "mday": parseInt(date[0]), "month": parseInt(date[1]) -1, "year": parseInt(date[2]) -1900, "wday": 1 } fetch("../time", {method: "POST", body: JSON.stringify(tobj)}).then(function() {textelement.remove(); getTime();}).then(function(x) {alert("Zeit/Datum erfolgreich geschrieben!")}).catch(function(x) {alert("Fehler beim Schreiben von Uhrzeit bzw. Datum!")}) } } function systoHC() { date = new Date(); tobj = { "seconds": date.getSeconds(), "minutes": date.getMinutes(), "hour": date.getHours(), "mday": date.getDate(), "month": date.getMonth(), "year": date.getYear(), "wday": 6 } fetch("../time", {method: "POST", body: JSON.stringify(tobj)}).then(function() {getTime();alert("Zeit erfolgreich mit RTC synchronisiert")}).catch(function(error) {"Fehler beim Synchronisieren mit der RTC!"}) } function updateAll() { getTime() getSystemTime() getAlarm() getNVRAM() } intervallID = 0; function configureIntervall() { if(intervallID == 0) { element = document.getElementById("intervaltext"); intervallID = setInterval(updateAll, parseInt(element.value) * 1000); } else { alert("Intervall ist bereits konfiguriert, stoppe die Aktualisierung bitte zuerst!") } } function removeItervall() { clearInterval(intervallID) intervallID = 0; }