that_one_nigga_you_k

melhor front que atualiza pra vários ESPs

May 21st, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.29 KB | None | 0 0
  1.  html
  2.  
  3. <!DOCTYPE html>
  4. <html lang="pt-br">
  5. <head>
  6.     <meta charset="UTF-8">
  7.     <title>Painel de Controle ESP32</title>
  8.     <style>
  9.         body {
  10.             font-family: Arial, sans-serif;
  11.             background: #f1f1f1;
  12.             padding: 20px;
  13.         }
  14.         h1 {
  15.             color: #333;
  16.         }
  17.         .esp {
  18.             background: white;
  19.             padding: 10px 15px;
  20.             margin-bottom: 10px;
  21.             border-radius: 8px;
  22.             box-shadow: 0 0 4px rgba(0,0,0,0.1);
  23.         }
  24.         .on {
  25.             color: green;
  26.         }
  27.         .off {
  28.             color: red;
  29.         }
  30.         .btn-toggle {
  31.             padding: 5px 10px;
  32.             font-weight: bold;
  33.             cursor: pointer;
  34.         }
  35.     </style>
  36. </head>
  37. <body>
  38.     <h1>Painel de Controle dos ESP32</h1>
  39.     <div id="esp-list">
  40.         Carregando dispositivos...
  41.     </div>
  42.  
  43.     <script>
  44.         function carregarDispositivos() {
  45.             fetch("/esp_list")
  46.                 .then(res => res.json())
  47.                 .then(data => {
  48.                     const container = document.getElementById("esp-list");
  49.                     container.innerHTML = "";
  50.  
  51.                     data.forEach(device => {
  52.                         const div = document.createElement("div");
  53.                         div.className = "esp";
  54.                         div.innerHTML = `
  55.                             <strong>ID:</strong> ${device.id}<br>
  56.                             <strong>Estado:</strong> <span class="${device.state ? 'on' : 'off'}">${device.state ? 'LIGADO' : 'DESLIGADO'}</span><br>
  57.                             <button class="btn-toggle" onclick="toggleEstado('${device.id}')">Alternar</button>
  58.                         `;
  59.                         container.appendChild(div);
  60.                     });
  61.                 });
  62.         }
  63.  
  64.         function toggleEstado(id) {
  65.             fetch("/control", {
  66.                 method: "POST",
  67.                 headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  68.                 body: `id=${id}`
  69.             }).then(() => carregarDispositivos());
  70.         }
  71.  
  72.         // Atualiza a lista de dispositivos a cada 5 segundos
  73.         setInterval(carregarDispositivos, 5000);
  74.         carregarDispositivos();
  75.     </script>
  76. </body>
  77. </html>
  78.  
Add Comment
Please, Sign In to add comment