Spaces:
Sleeping
Sleeping
Update settings.html
Browse files- settings.html +97 -143
settings.html
CHANGED
|
@@ -319,173 +319,127 @@ document.addEventListener("DOMContentLoaded", function () {
|
|
| 319 |
|
| 320 |
|
| 321 |
<script>
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
var xhr = new XMLHttpRequest();
|
| 326 |
-
xhr.open("GET", "/
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
xhr.send();
|
| 329 |
-
}
|
| 330 |
-
</script>
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
<script>
|
| 334 |
-
document.getElementById("st_table").addEventListener("click", function() {
|
| 335 |
-
var baseUrl = window.location.origin;
|
| 336 |
-
var targetUrl = baseUrl + "/table";
|
| 337 |
-
window.location.href = targetUrl;
|
| 338 |
-
});
|
| 339 |
-
</script>
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
<script>
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
function updateValues(data) {
|
| 353 |
-
document.getElementById("pH_eep").textContent = data.ph_eep;
|
| 354 |
-
document.getElementById("ph_on_eep").textContent = data.ph_on_eep;
|
| 355 |
-
document.getElementById("ec_eep").textContent = data.ec_eep;
|
| 356 |
-
document.getElementById("ec_A_eep").textContent = data.ec_A_eep;
|
| 357 |
-
document.getElementById("ec_B_eep").textContent = data.ec_B_eep;
|
| 358 |
-
document.getElementById("ec_C_eep").textContent = data.ec_C_eep;
|
| 359 |
-
document.getElementById("l_ON_h_eep").textContent = data.l_ON_h_eep;
|
| 360 |
-
document.getElementById("l_ON_m_eep").textContent = data.l_ON_m_eep;
|
| 361 |
-
document.getElementById("l_OFF_h_eep").textContent = data.l_OFF_h_eep;
|
| 362 |
-
document.getElementById("l_OFF_m_eep").textContent = data.l_OFF_m_eep;
|
| 363 |
-
document.getElementById("t_Voz_eep").textContent = data.t_Voz_eep;
|
| 364 |
-
|
| 365 |
-
}
|
| 366 |
-
|
| 367 |
-
function fetchValues() {
|
| 368 |
-
var xhr = new XMLHttpRequest();
|
| 369 |
-
xhr.open("GET", "/settings_api", true);
|
| 370 |
-
xhr.setRequestHeader("Content-Type", "application/json");
|
| 371 |
-
xhr.onreadystatechange = function () {
|
| 372 |
-
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 373 |
-
var response = JSON.parse(xhr.responseText);
|
| 374 |
-
updateValues(response);
|
| 375 |
-
}
|
| 376 |
-
};
|
| 377 |
-
xhr.send();
|
| 378 |
-
}
|
| 379 |
-
|
| 380 |
-
fetchValues();
|
| 381 |
-
setInterval(fetchValues, 10000);
|
| 382 |
-
</script>
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
-
|
|
|
|
|
|
|
| 392 |
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
var pHValue = document.getElementById("pH_set").value;
|
| 396 |
var xhr = new XMLHttpRequest();
|
| 397 |
-
xhr.open("GET", "/
|
| 398 |
xhr.send();
|
| 399 |
-
}
|
| 400 |
-
</script>
|
| 401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
-
<script>
|
| 404 |
document.getElementById("ph_on_set_but").addEventListener("click", function() {
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
xhr.send();
|
| 409 |
-
});
|
| 410 |
-
</script>
|
| 411 |
|
| 412 |
-
|
| 413 |
-
<script>
|
| 414 |
document.getElementById("ec_set_but").addEventListener("click", function() {
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
xhr.send();
|
| 419 |
-
});
|
| 420 |
-
</script>
|
| 421 |
-
|
| 422 |
-
<script>
|
| 423 |
-
document.getElementById("ec_A_set_but").addEventListener("click", function() {
|
| 424 |
-
var ec_A_setValue = document.getElementById("ec_A_set").value;
|
| 425 |
-
var xhr = new XMLHttpRequest();
|
| 426 |
-
xhr.open("GET", "/ec_A_set?value=" + ec_A_setValue, true);
|
| 427 |
-
xhr.send();
|
| 428 |
-
});
|
| 429 |
-
</script>
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
|
| 432 |
-
<script>
|
| 433 |
document.getElementById("ec_B_set_but").addEventListener("click", function() {
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
xhr.send();
|
| 438 |
-
});
|
| 439 |
-
</script>
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
<script>
|
| 443 |
-
document.getElementById("ec_C_set_but").addEventListener("click", function() {
|
| 444 |
-
var ec_C_setValue = document.getElementById("ec_C_set").value;
|
| 445 |
-
var xhr = new XMLHttpRequest();
|
| 446 |
-
xhr.open("GET", "/ec_C_set?value=" + ec_C_setValue, true);
|
| 447 |
-
xhr.send();
|
| 448 |
-
});
|
| 449 |
-
</script>
|
| 450 |
|
| 451 |
-
<script>
|
| 452 |
document.getElementById("ec_C_set_but").addEventListener("click", function() {
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
xhr.send();
|
| 457 |
-
});
|
| 458 |
-
</script>
|
| 459 |
-
|
| 460 |
|
| 461 |
-
|
| 462 |
-
<script>
|
| 463 |
document.getElementById("l_ON_set").addEventListener("click", function() {
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
xhr.send();
|
| 469 |
-
});
|
| 470 |
-
</script>
|
| 471 |
|
| 472 |
-
<script>
|
| 473 |
document.getElementById("l_OFF_set").addEventListener("click", function() {
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
});
|
| 480 |
-
</script>
|
| 481 |
-
|
| 482 |
-
<script>
|
| 483 |
document.getElementById("t_Voz_set").addEventListener("click", function() {
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
</body>
|
| 491 |
</html>
|
|
|
|
| 319 |
|
| 320 |
|
| 321 |
<script>
|
| 322 |
+
let fetchInterval = null;
|
| 323 |
+
let timeoutReset = null;
|
| 324 |
+
|
| 325 |
+
function updateValues(data) {
|
| 326 |
+
document.getElementById("pH_eep").textContent = data.ph_eep;
|
| 327 |
+
document.getElementById("ph_on_eep").textContent = data.ph_on_eep;
|
| 328 |
+
document.getElementById("ec_eep").textContent = data.ec_eep;
|
| 329 |
+
document.getElementById("ec_A_eep").textContent = data.ec_A_eep;
|
| 330 |
+
document.getElementById("ec_B_eep").textContent = data.ec_B_eep;
|
| 331 |
+
document.getElementById("ec_C_eep").textContent = data.ec_C_eep;
|
| 332 |
+
document.getElementById("l_ON_h_eep").textContent = data.l_ON_h_eep;
|
| 333 |
+
document.getElementById("l_ON_m_eep").textContent = data.l_ON_m_eep;
|
| 334 |
+
document.getElementById("l_OFF_h_eep").textContent = data.l_OFF_h_eep;
|
| 335 |
+
document.getElementById("l_OFF_m_eep").textContent = data.l_OFF_m_eep;
|
| 336 |
+
document.getElementById("t_Voz_eep").textContent = data.t_Voz_eep;
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
function fetchValues() {
|
| 340 |
var xhr = new XMLHttpRequest();
|
| 341 |
+
xhr.open("GET", "/settings_api", true);
|
| 342 |
+
xhr.setRequestHeader("Content-Type", "application/json");
|
| 343 |
+
xhr.onreadystatechange = function () {
|
| 344 |
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
| 345 |
+
var response = JSON.parse(xhr.responseText);
|
| 346 |
+
updateValues(response);
|
| 347 |
+
}
|
| 348 |
+
};
|
| 349 |
xhr.send();
|
| 350 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
function startFetching(intervalTime) {
|
| 353 |
+
if (fetchInterval) clearInterval(fetchInterval);
|
| 354 |
+
fetchInterval = setInterval(fetchValues, intervalTime);
|
| 355 |
+
}
|
| 356 |
|
| 357 |
+
function resetToSlowUpdate() {
|
| 358 |
+
startFetching(10000); // 10 секунд
|
| 359 |
+
timeoutReset = null;
|
| 360 |
+
}
|
| 361 |
|
| 362 |
+
function activateFastUpdate() {
|
| 363 |
+
startFetching(2500); // 2.5 секунды
|
| 364 |
+
if (timeoutReset) clearTimeout(timeoutReset);
|
| 365 |
+
timeoutReset = setTimeout(resetToSlowUpdate, 5 * 60 * 1000); // 5 минут
|
| 366 |
+
}
|
| 367 |
|
| 368 |
+
function buttonHandler(url) {
|
| 369 |
+
var xhr = new XMLHttpRequest();
|
| 370 |
+
xhr.open("GET", url, true);
|
| 371 |
+
xhr.send();
|
| 372 |
+
activateFastUpdate(); // Ускоряем обновление
|
| 373 |
+
}
|
| 374 |
|
| 375 |
+
// Стартуем медленно
|
| 376 |
+
fetchValues();
|
| 377 |
+
startFetching(10000);
|
| 378 |
|
| 379 |
+
// Первичный вызов
|
| 380 |
+
window.onload = function() {
|
|
|
|
| 381 |
var xhr = new XMLHttpRequest();
|
| 382 |
+
xhr.open("GET", "/set_res", true);
|
| 383 |
xhr.send();
|
| 384 |
+
};
|
|
|
|
| 385 |
|
| 386 |
+
// Таблица
|
| 387 |
+
document.getElementById("st_table").addEventListener("click", function() {
|
| 388 |
+
activateFastUpdate();
|
| 389 |
+
var baseUrl = window.location.origin;
|
| 390 |
+
var targetUrl = baseUrl + "/table";
|
| 391 |
+
window.location.href = targetUrl;
|
| 392 |
+
});
|
| 393 |
+
|
| 394 |
+
// Назначение обработчиков для всех кнопок
|
| 395 |
+
document.getElementById("pH_set_but").addEventListener("click", function() {
|
| 396 |
+
let val = document.getElementById("pH_set").value;
|
| 397 |
+
buttonHandler("/pH_set?value=" + val);
|
| 398 |
+
});
|
| 399 |
|
|
|
|
| 400 |
document.getElementById("ph_on_set_but").addEventListener("click", function() {
|
| 401 |
+
let val = document.getElementById("ph_on_set").value;
|
| 402 |
+
buttonHandler("/ph_on_set?value=" + val);
|
| 403 |
+
});
|
|
|
|
|
|
|
|
|
|
| 404 |
|
|
|
|
|
|
|
| 405 |
document.getElementById("ec_set_but").addEventListener("click", function() {
|
| 406 |
+
let val = document.getElementById("ec_set").value;
|
| 407 |
+
buttonHandler("/EC_set?value=" + val);
|
| 408 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
+
document.getElementById("ec_A_set_but").addEventListener("click", function() {
|
| 411 |
+
let val = document.getElementById("ec_A_set").value;
|
| 412 |
+
buttonHandler("/ec_A_set?value=" + val);
|
| 413 |
+
});
|
| 414 |
|
|
|
|
| 415 |
document.getElementById("ec_B_set_but").addEventListener("click", function() {
|
| 416 |
+
let val = document.getElementById("ec_B_set").value;
|
| 417 |
+
buttonHandler("/ec_B_set?value=" + val);
|
| 418 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
|
|
|
| 420 |
document.getElementById("ec_C_set_but").addEventListener("click", function() {
|
| 421 |
+
let val = document.getElementById("ec_C_set").value;
|
| 422 |
+
buttonHandler("/ec_C_set?value=" + val);
|
| 423 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
|
|
|
|
|
|
|
| 425 |
document.getElementById("l_ON_set").addEventListener("click", function() {
|
| 426 |
+
let h = document.getElementById("l_ON_h_set").value;
|
| 427 |
+
let m = document.getElementById("l_ON_m_set").value;
|
| 428 |
+
buttonHandler("/l_ON_set?l_ON_h_set=" + h + "&l_ON_m_set=" + m);
|
| 429 |
+
});
|
|
|
|
|
|
|
|
|
|
| 430 |
|
|
|
|
| 431 |
document.getElementById("l_OFF_set").addEventListener("click", function() {
|
| 432 |
+
let h = document.getElementById("l_OFF_h_set").value;
|
| 433 |
+
let m = document.getElementById("l_OFF_m_set").value;
|
| 434 |
+
buttonHandler("/l_OFF_set?l_OFF_h_set=" + h + "&l_OFF_m_set=" + m);
|
| 435 |
+
});
|
| 436 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
document.getElementById("t_Voz_set").addEventListener("click", function() {
|
| 438 |
+
let val = document.getElementById("t_Voz_eep_set").value;
|
| 439 |
+
buttonHandler("/t_Voz_eep_set?value=" + val);
|
| 440 |
+
});
|
| 441 |
+
|
| 442 |
+
</script>
|
| 443 |
+
|
| 444 |
</body>
|
| 445 |
</html>
|