// // Nach dem Laden des Dokumentes: $(document).ready(function() { console.log("Es geht los"); const URL = "switch/"; const brenndauer = 300; // Dauer der Anzeige in Sekunden const checktime = 5000000; // alle 30sec Zustand prüfen let status = ""; let tr; let interval; $('#versn').html("V " + VERSION + ' ' + VDATE); // Vesion anzeigen $("#auszeile").hide(); // Meldezeile AUS schalten // sendCommand(URL,"PowerOnState%200"); // OFF bei Power ON // sendCommand(URL,"PulseTime%20"+(brenndauer+100)); // Brenndauer einstellen sendCommand(URL,"get_status") .then(st => { console.log("Status = ",st); checkStatus(st); }); $("#schalter").click(function() { let message; clearTimeout(interval); if (status == 'ON') { console.log("Sende OFF") sendCommand(URL,"switch_off") .then(st => { console.log("Status = ", st); checkStatus(st); interval = setInterval(sendTimedCommand,5000); }); } else { console.log("Sende ON") sendCommand(URL,"switch_on") .then(st => { console.log("Status = ",st); checkStatus(st); interval = setInterval(sendTimedCommand,5000); }); } }); function sendCommand(url,cmnd) { const p = new Promise((resolve, reject) => { $.getJSON(url + cmnd, function (data, err) { // AJAX Call if (err != 'success') { reject(err); alert("Fehler
" + err); // if error, show it } else { console.log("gekommen: ", data); resolve(data.status); } }); }); return p; } function sendTimedCommand() { console.log("time check"); sendCommand(URL,'check') .then(st => { console.log("Timed Status= ", st); status = st; if (st != 'pending') { clearTimeout(tr); if (st == 'ON') { $('#schalter').html('Laufschrift AUS schalten'); $('#status').text('EIN'); $('#statuszeile').addClass('machrot'); $('#auszeile').show(); } else { $('#schalter').html('Laufschrift EIN schalten'); $('#status').text('AUS'); $('#statuszeile').removeClass('machrot'); $('#auszeile').hide(); } } }); } function checkStatus(st) { if (st == 'pending') { tr = setTimeout(sendTimedCommand,500); } } });