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_on", "out_tim_on");
  44. let xhr = new XMLHttpRequest();
  45. xhr.onreadystatechange = function(){
  46. if(xhr.readyState == 4) {
  47. if (xhr.status == 200){
  48. console.log(xhr.responseText);
  49. terminal = document.getElementById("term");
  50. autoscroll = document.getElementById("scroll");
  51. terminal.innerHTML += xhr.responseText;
  52. if(autoscroll.checked)
  53. terminal.scrollTop = terminal.scrollHeight;
  54. }
  55. else {
  56. console.log("status:", xhr.status);
  57. }
  58. }
  59. }
  60. function reloadTerminal() {
  61. xhr.open("POST", "/terminal", true);
  62. xhr.send();
  63. setTimeout(reloadTerminal, 1000);
  64. };
  65. reloadTerminal();
  66. function clearTerminal() {
  67. document.getElementById("term").innerHTML = '';
  68. }