ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

input.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. let rangeValues = {};
  2. let xhrUpd = new XMLHttpRequest();
  3. xhrUpd.onreadystatechange = function(){
  4. if(xhrUpd.readyState == 4) {
  5. if (xhrUpd.status == 200){
  6. console.log(xhrUpd.responseText);
  7. }
  8. else {
  9. console.log("status:", xhrUpd.status);
  10. }
  11. }
  12. }
  13. function reloadRangeValues() {
  14. let url = "/update";
  15. // if there are scheduled updates, send them
  16. if(Object.keys(rangeValues).length > 0) {
  17. let params = [];
  18. for(let p in rangeValues)
  19. params.push(encodeURIComponent(p) + "=" + encodeURIComponent(rangeValues[p]));
  20. params = params.join("&");
  21. xhrUpd.open("POST", url, true);
  22. xhrUpd.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  23. xhrUpd.send(params);
  24. rangeValues = {};
  25. }
  26. setTimeout(reloadRangeValues, 1000);
  27. };
  28. reloadRangeValues();
  29. function sendRangeValue(range, val) {
  30. rangeValues[range] = val;
  31. console.log(rangeValues);
  32. };
  33. // connect actions to range inputs
  34. function rangeToOutput(range, output) {
  35. document.getElementById(range).oninput = function() {
  36. document.getElementById(output).innerHTML = this.value;
  37. sendRangeValue(this.id, this.value);
  38. }
  39. }
  40. rangeToOutput("range_act_pwm", "out_act_pwm");
  41. rangeToOutput("range_idl_pwm", "out_idl_pwm");
  42. rangeToOutput("range_tim_sta", "out_tim_sta");
  43. rangeToOutput("range_tim_ldr", "out_tim_ldr");
  44. rangeToOutput("range_ldr_shw", "out_ldr_shw");
  45. let xhr = new XMLHttpRequest();
  46. xhr.onreadystatechange = function(){
  47. if(xhr.readyState == 4) {
  48. if (xhr.status == 200){
  49. console.log(xhr.responseText);
  50. terminal = document.getElementById("term");
  51. autoscroll = document.getElementById("scroll");
  52. terminal.innerHTML += xhr.responseText;
  53. if(autoscroll.checked)
  54. terminal.scrollTop = terminal.scrollHeight;
  55. }
  56. else {
  57. console.log("status:", xhr.status);
  58. }
  59. }
  60. }
  61. function reloadTerminal() {
  62. xhr.open("POST", "/terminal", true);
  63. xhr.send();
  64. setTimeout(reloadTerminal, 1000);
  65. };
  66. reloadTerminal();
  67. function clearTerminal() {
  68. document.getElementById("term").innerHTML = '';
  69. }