123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- fetch("https://169.254.175.168:8888/device").then( function(text) { return text.text() } ).then( function(text2) { element = document.getElementById("deviceheader"); element.innerText = text2} )
- function getTime() {
- fetch("https://169.254.175.168:8888/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() + " " + addZero(date.getHours()) + ":" + addZero(date.getMinutes()) + ":" + addZero(date.getSeconds());
- }
- function getAlarm() {
- fetch("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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("https://169.254.175.168:8888/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
- }
- console.log(tobj)
- fetch("https://169.254.175.168:8888/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;
- }
|