jp112

esp32camweb

Jan 2nd, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.  
  5. <head>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <style>
  9. body { text-align: center; }
  10. .vert { margin-bottom: 10%;}
  11. .hori { margin-bottom: 0%; }
  12. .slider { width: 300px; }
  13. </style>
  14. </head>
  15.  
  16. <body>
  17. <div>
  18. <img src="/pic" id="picimg" width="70%">
  19. </div>
  20. <div>
  21. <p>
  22. <button id="reloadBtn" onclick="location.reload();">Aktualisieren</button>
  23. <button id="srcBtn" onclick="location.href='?show=video';">Video-Ansicht</button>
  24. <button id="flashlightBtn" onclick="toggleFlashlight()">Blitzlicht anschalten</button>
  25. <input type="range" min="180" max="0" value="90" class="slider" id="servoSlider" onchange="SetServoPos(this.value)" />
  26. </p>
  27. </div>
  28.  
  29. <script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  30. <script>
  31.  
  32. var slider = document.getElementById("servoSlider");
  33. var picimg = document.getElementById("picimg");
  34. var reloadBtn = document.getElementById("reloadBtn");
  35. var srcBtn = document.getElementById("srcBtn");
  36. var flashlightBtn = document.getElementById("flashlightBtn");
  37. var flashlightState = 'aus';
  38.  
  39. $.ajaxSetup({
  40. timeout: 1000
  41. });
  42.  
  43. function ajaxErrorHandler(err) {
  44. // TODO: implement some error handling
  45. }
  46.  
  47. function GetServoPos(){
  48. $.get('/get?item=servopos')
  49. .done(function(data) {
  50. slider.value = data;
  51. })
  52. .fail(ajaxErrorHandler);
  53. }
  54.  
  55. function GetFlashlightState(){
  56. $.get('/get?item=flashlight')
  57. .done(function(data) {
  58. flashlightState = data;
  59. flashlightBtn.innerText = "Blitzlicht " + (data === 'an' ? 'ausschalten' : 'anschalten');
  60. })
  61. .fail(ajaxErrorHandler);
  62. }
  63.  
  64. function toggleFlashlight() {
  65. $.post('/set', 'flashlight=' + (flashlightState === 'an' ? '0' : '1'))
  66. .fail(ajaxErrorHandler);
  67. }
  68.  
  69. slider.oninput = function() {
  70. slider.value = this.value;
  71. }
  72.  
  73. function SetServoPos(pos) {
  74. $.post("/set","servopos=" + pos)
  75. .fail(ajaxErrorHandler);
  76. }
  77.  
  78. GetServoPos();
  79. GetFlashlightState();
  80.  
  81. var queryStr = window.location.search;
  82. console.log(queryStr);
  83. if (queryStr === "?show=video") {
  84. reloadBtn.style.display = "none";
  85. // Warum mit FQDN und nicht einfach "/vid" ?
  86. picimg.src = "http://"+window.location.hostname+":81/vid";
  87. srcBtn.innerHTML = "Bild-Ansicht";
  88. srcBtn.setAttribute("onClick", "location.href='?show=picture';");
  89. }
  90.  
  91. if (queryStr === "?show=picture") {
  92. reloadBtn.style.display = "inline";
  93. picimg.src = "/pic";
  94. srcBtn.innerHTML = "Video-Ansicht";
  95. srcBtn.setAttribute("onClick", "location.href='?show=video';");
  96. }
  97.  
  98. </script>
  99. </body>
  100.  
  101. </html>
Advertisement
Add Comment
Please, Sign In to add comment