that_one_nigga_you_k

front final

Jun 6th, 2025 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>ESP32-CAM Controle</title>
  7.     <style>
  8.         body {
  9.             font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  10.             display: flex;
  11.             flex-direction: column;
  12.             align-items: center;
  13.             justify-content: center;
  14.             min-height: 100vh;
  15.             margin: 0;
  16.             background-color: #f0f2f5;
  17.             color: #333;
  18.         }
  19.         .container {
  20.             text-align: center;
  21.             background-color: white;
  22.             padding: 2rem;
  23.             border-radius: 12px;
  24.             box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  25.         }
  26.         h1 {
  27.             margin-top: 0;
  28.             color: #1c1e21;
  29.         }
  30.         #photo-display {
  31.             max-width: 100%;
  32.             width: 320px;
  33.             height: 240px;
  34.             border: 1px solid #ddd;
  35.             border-radius: 8px;
  36.             margin-top: 1rem;
  37.             background-color: #eee;
  38.             object-fit: cover;
  39.         }
  40.         #flash-button {
  41.             margin-top: 1.5rem;
  42.             padding: 0.75rem 1.5rem;
  43.             font-size: 1rem;
  44.             font-weight: 600;
  45.             border-radius: 8px;
  46.             border: none;
  47.             cursor: pointer;
  48.             color: white;
  49.             transition: background-color 0.3s, transform 0.1s;
  50.         }
  51.         #flash-button.on {
  52.             background-color: #f5b400; /* Laranja/Amarelo para ON */
  53.         }
  54.         #flash-button.off {
  55.             background-color: #4CAF50; /* Verde para OFF (ação de ligar) */
  56.         }
  57.         #flash-button:active {
  58.             transform: scale(0.98);
  59.         }
  60.         #status {
  61.             margin-top: 1rem;
  62.             font-size: 0.9rem;
  63.             color: #666;
  64.         }
  65.     </style>
  66. </head>
  67. <body>
  68.  
  69.     <div class="container">
  70.         <h1>Controle da Câmera ESP32</h1>
  71.         <img id="photo-display" src="/latest-photo" alt="Última foto da câmera">
  72.         <button id="flash-button">Carregando...</button>
  73.         <p id="status">Buscando estado do flash...</p>
  74.     </div>
  75.  
  76.     <script>
  77.         const photoDisplay = document.getElementById('photo-display');
  78.         const flashButton = document.getElementById('flash-button');
  79.         const statusEl = document.getElementById('status');
  80.         let isFlashOn = false;
  81.  
  82.         // Função para atualizar o texto e a cor do botão
  83.         function updateButtonUI() {
  84.             if (isFlashOn) {
  85.                 flashButton.textContent = 'Desligar Flash';
  86.                 flashButton.className = 'on';
  87.             } else {
  88.                 flashButton.textContent = 'Ligar Flash';
  89.                 flashButton.className = 'off';
  90.             }
  91.         }
  92.  
  93.         // Função para enviar o comando do flash para o servidor
  94.         async function toggleFlash() {
  95.             const newCommand = isFlashOn ? 'FLASH_OFF' : 'FLASH_ON';
  96.             try {
  97.                 const response = await fetch('/command', {
  98.                     method: 'POST',
  99.                     headers: { 'Content-Type': 'application/json' },
  100.                     body: JSON.stringify({ command: newCommand })
  101.                 });
  102.                 const result = await response.json();
  103.  
  104.                 if (response.ok) {
  105.                     isFlashOn = (result.newCommand === 'FLASH_ON');
  106.                     statusEl.textContent = `Comando enviado: ${result.newCommand}.`;
  107.                     updateButtonUI();
  108.                 } else {
  109.                     statusEl.textContent = `Erro: ${result.message}`;
  110.                 }
  111.             } catch (error) {
  112.                 console.error('Erro ao enviar comando:', error);
  113.                 statusEl.textContent = 'Erro de conexão com o servidor.';
  114.             }
  115.         }
  116.  
  117.         // Função para buscar o estado inicial do flash no servidor
  118.         async function getInitialFlashState() {
  119.              try {
  120.                 const response = await fetch('/command'); // GET request
  121.                 const command = await response.text();
  122.                 isFlashOn = (command === 'FLASH_ON');
  123.                 updateButtonUI();
  124.                 statusEl.textContent = `Estado atual do flash: ${command}.`;
  125.             } catch (error) {
  126.                 console.error('Erro ao buscar estado inicial:', error);
  127.                 statusEl.textContent = 'Não foi possível obter o estado do flash.';
  128.             }
  129.         }
  130.        
  131.         // Função para atualizar a imagem periodicamente
  132.         function refreshImage() {
  133.             // Adiciona um timestamp para evitar que o navegador use a imagem do cache
  134.             photoDisplay.src = `/latest-photo?t=${new Date().getTime()}`;
  135.         }
  136.  
  137.         // Event listener para o botão
  138.         flashButton.addEventListener('click', toggleFlash);
  139.        
  140.         // Inicia a aplicação
  141.         // 1. Busca o estado inicial assim que a página carrega
  142.         getInitialFlashState();
  143.         // 2. Define um intervalo para atualizar a imagem a cada 5 segundos
  144.         setInterval(refreshImage, 5000);
  145.  
  146.     </script>
  147. </body>
  148. </html>
  149.  
Add Comment
Please, Sign In to add comment