
/************************************************************************************* 
	01.07.2025
	Webseite zu 17_HTU_WebServer_WebSocket
**************************************************************************************/

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <title>ESP8266 Web Server</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" href="data:,">
  <style>
  html {
    font-family: Arial, Helvetica, sans-serif;
    text-align: center;
  }
  h1 {
    font-size: 1.4rem;
    color: white;
  }
  h2{
    font-size: 1.2rem;
    font-weight: bold;
    color: #143642;
  }
  .topnav {
    overflow: hidden;
    background-color: #143642;
  }
  body {
    margin: 0;
  }
  .content {
    padding: 15px;
    max-width: 260px;
    margin: 0 auto;
  }
  .card {
    max-width: 260px;
    background-color: #F8F7F9;;
    box-shadow: 2px 2px 12px 1px rgba(140,140,140,.5);
    padding-top:8px;
    padding-bottom:15px;
  }
  .card-grid { 
    max-width: 280; 
    margin: 0 auto; 
    display: grid; 
	gap: 0.6rem; 
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
  }  
  .button {
    padding: 15px 50px;
    font-size: 16px;
    text-align: center;
    outline: none;
    color: #fff;
    background-color: #0f8b8d;
    border: none;
    border-radius: 5px;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
   }
   /*.button:hover {background-color: #0f8b8d}*/
   .button:active {
     background-color: #0f8b8d;
     box-shadow: 2 2px #CDCDCD;
     transform: translateY(2px);
   }
   .state {
     font-size: 1.1rem;
     color:#8c8c8c;
     font-weight: bold;
   }
  </style>
<title>ESP01 Web Server</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
</head>
<body>
  <div class="topnav">
    <h1>ESP8266 WebServer mit WebSocket</h1>
  </div>
  <div class="content">
    <div class="card-grid">
    <div class="card">
      <h2>Temperatur Aussen</h2>
      <p class="state"> <span id="Temp_out">%Temperatur_out%</span> &deg;C</p>
    </div>
    <div class="card">
      <h2>Temperatur Innen</h2>
      <p class="state"> <span id="Temp_in">%Temperatur_in%</span> &deg;C</p>
    </div>
    <div class="card">
      <h2>Output - GPIO 0</h2>
      <p class="state">state: <span id="state">%STATE%</span></p>
      <p><button id="button" class="button">Toggle</button></p>
    </div>
    </div>
  </div>
<script>
  var gateway = `ws://${window.location.hostname}/ws`;
  var websocket;
  window.addEventListener('load', onLoad);
  
  function initWebSocket() {
    console.log('Trying to open a WebSocket connection...');
    websocket = new WebSocket(gateway);
    websocket.onopen    = onOpen;
    websocket.onclose   = onClose;
    websocket.onmessage = onMessage; // <-- add this line
  }
  function onOpen(event) {
    console.log('Connection opened');
  }
  function onClose(event) {
    console.log('Connection closed');
    setTimeout(initWebSocket, 2000);
  }
  function onMessage(event) {
    var state;
    if (event.data == "0"){
      state = "OFF";
    }
    else{
      state = "ON";
    }
    document.getElementById('state').innerHTML = state;
  }
  function onLoad(event) {
    initWebSocket();
    initButton();
  }
  function initButton() {
    document.getElementById('button').addEventListener('click', toggle);
  }
  function toggle(){
    websocket.send('toggle');
  }
</script>
</body>
</html>)rawliteral";

