# ESP32 HTML Script

**URL:** <https://forum.arduino.cc/t/esp32-html-script/1349680>\
**Category:** Deutsch\
**Created:** [February 2, 2025, 12:29pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680 "2025-02-02T12:29:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![hypergamer7391](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hypergamer7391/32/1156822_2.png) [@hypergamer7391](https://forum.arduino.cc/u/hypergamer7391)\
**Post date:** [February 2, 2025, 12:29pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/1 "2025-02-02T12:29:57Z")

</div>

Moin zusammen,  
Ich sitze gerade an einem Projekt mit meinem ESP32 und ich würde gerne eine website damit verbinden. Ich habe dazu schon die Wlan Verbindung und meine webserver datei sieht im moment so aus:

```arduino
#include "webserver.h"
#include "schranke.h"

String header;
String output26State = "off";
String output27State = "off";
String output_state = "nicht festgelegt";
const int output26 = 26;
const int output27 = 27;

void handleClient() {
    WiFiClient client = server.available();

    if (client) {
        unsigned long currentTime = millis();
        unsigned long previousTime = currentTime;
        const long timeoutTime = 2000;

        Serial.println("New Client.");
        String currentLine = "";

        while (client.connected() && currentTime - previousTime <= timeoutTime) {
            currentTime = millis();
            if (client.available()) {
                char c = client.read();
                Serial.write(c);
                header += c;

                if (c == '\n') {
                    if (currentLine.length() == 0) {
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-type:text/html");
                        client.println("Connection: close");
                        client.println();

                        if (header.indexOf("GET /26/on") >= 0) {
                            Serial.println("GPIO 26 on");
                            output26State = "on";
                            digitalWrite(output26, HIGH);
                            auf();
                        } else if (header.indexOf("GET /26/off") >= 0) {
                            Serial.println("GPIO 26 off");
                            output26State = "off";
                            digitalWrite(output26, LOW);
                        } else if (header.indexOf("GET /27/on") >= 0) {
                            Serial.println("GPIO 27 on");
                            output27State = "on";
                            digitalWrite(output27, HIGH);
                        } else if (header.indexOf("GET /27/off") >= 0) {
                            Serial.println("GPIO 27 off");
                            output27State = "off";
                            digitalWrite(output27, LOW);
                        }
                        if(state = true){
                          Serial.println(state);
                          output_state = "AUF";
                        }
                        else{
                          output_state = "ZU";
                          Serial.println(state);
                        }

                        client.println("<!DOCTYPE html><html>");
                        client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
                        client.println("<link rel=\"icon\" href=\"data:,\">");
                        client.println("<style>html { font-family: Helvetica; text-align: center;}");
                        client.println(".button { background-color: #4CAF50; color: white; padding: 16px 40px;");
                        client.println("font-size: 30px; margin: 2px; cursor: pointer;}");
                        client.println(".button2 {background-color: #555555;}</style></head>");

                        client.println("<body><h1>ESP32 Web Server</h1>");
                        client.println("<p>GPIO 26 - State " + output26State + "</p>");
                        client.println(output26State == "off" ? "<p><a href=\"/26/on\"><button class=\"button\">ON</button></a></p>"
                                                              : "<p><a href=\"/26/off\"><button class=\"button button2\">OFF</button></a></p>");
                        client.println("<p>Aktueller schrnaken zustand" + output_state + "</p>");
                        client.println("<p>GPIO 27 - State " + output27State + "</p>");
                        client.println(output27State == "off" ? "<p><a href=\"/27/on\"><button class=\"button\">ON</button></a></p>"
                                                              : "<p><a href=\"/27/off\"><button class=\"button button2\">OFF</button></a></p>");
                        client.println("</body></html>");
                        client.println();

                        break;
                    } else {
                        currentLine = "";
                    }
                } else if (c != '\r') {
                    currentLine += c;
                }
            }
        }
        header = "";
        client.stop();
        Serial.println("Client disconnected.");
    }
}

```

Nun frage ich mich ob man das auch alles in einer externe HTML Datei auslagern kann.

Vielen Dank für die Hilfe!

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [February 2, 2025, 12:34pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/2 "2025-02-02T12:34:00Z")

</div>

Ja, die kannst Du im Dateisystem des ESP32 (LittleFS) speichern.  
Beispiele dazu gibt es bei [Fips](https://fipsok.de/). Eine Einführung von @agmue in die Website von Fips gibt es [hier](https://www.wikinger-tommy.de/arduino/einfuehrung_fips.html).

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![hypergamer7391](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hypergamer7391/32/1156822_2.png) [@hypergamer7391](https://forum.arduino.cc/u/hypergamer7391)\
**Post date:** [February 2, 2025, 12:38pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/3 "2025-02-02T12:38:01Z")

</div>

Was ist wenn ich ein unabhängige website mit html css js habe kann ich dadrauf daten übermitteln wie zum beispiel sensor Daten

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [February 2, 2025, 12:54pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/4 "2025-02-02T12:54:07Z")

</div>

Klar, z.B. über Javascript und die Fetch-API.

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![zwieblum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zwieblum/32/427702_2.png) [@zwieblum](https://forum.arduino.cc/u/zwieblum)\
**Post date:** [February 2, 2025, 1:16pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/5 "2025-02-02T13:16:30Z")

</div>

oder Websockets

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [February 2, 2025, 1:18pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/6 "2025-02-02T13:18:04Z")

</div>

oder AJAX 😉

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![zwieblum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zwieblum/32/427702_2.png) [@zwieblum](https://forum.arduino.cc/u/zwieblum)\
**Post date:** [February 2, 2025, 2:31pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/7 "2025-02-02T14:31:13Z")

</div>

oder FROSCH

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [February 2, 2025, 4:24pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/8 "2025-02-02T16:24:10Z")

</div>

> [@hypergamer7391](#):
>
> Was ist wenn ich ein unabhängige website mit html css js habe kann ich dadrauf daten übermitteln wie zum beispiel sensor Daten

Kannst du das näher beschreiben?  
Wo ist diese "unabhängige website" gehostet?

---

<div class="post-metadata">

**Author:** ![michael\_x](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/michael_x/32/628623_2.png) [@michael\_x](https://forum.arduino.cc/u/michael_x)\
**Post date:** [February 2, 2025, 4:26pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/9 "2025-02-02T16:26:49Z")

</div>

> [@zwieblum](#):
>
> FROSCH

Ohne [Link](https://de.wikipedia.org/wiki/Frosch) finde ich da nicht, was du meinen könntest.

---

<div class="post-metadata">

**Author:** ![zwieblum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zwieblum/32/427702_2.png) [@zwieblum](https://forum.arduino.cc/u/zwieblum)\
**Post date:** [February 2, 2025, 5:06pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/10 "2025-02-02T17:06:58Z")

</div>

AJAX:

> **[Ajax Aroma Sensation Lavender &amp; Magnolia All-Purpose Cleaner Pack of 6 (6 x...](https://www.amazon.de/-/en/Sensation-Lavender-Magnolia-All-Purpose-Cleaner/dp/B00SCUJ7NQ)**
>
> Ajax Aroma Sensation Lavender & Magnolia All-Purpose Cleaner Pack of 6 (6 x 1 L);

FROSCH:

> **[Frosch Neutral Cleaner, Pack of 6 (6 x 1 L) : Amazon.de: Health &amp; Personal...](https://www.amazon.de/-/en/Frosch-Neutral-Cleaner-Pack/dp/B00Q8PC5V8)**
>
> The Frosch Neutral Cleaner is a natural and very economical all-purpose cleaner for the gentle cleaning of floors, wood, kitchen and bathroom furniture as well as tiles and sanitary equipment. Thanks to pH neutrality, the formula with plant-based...

.... ja ja ja Karneval kommt erst ... ich konnte es mir trotzdem nicht verkneifen ... 🕶

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [February 2, 2025, 5:27pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/11 "2025-02-02T17:27:17Z")

</div>

Dann der Vollständigkeit halber: [AJAX](https://de.wikipedia.org/wiki/Ajax_(Programmierung)).

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [February 2, 2025, 6:04pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/12 "2025-02-02T18:04:02Z")

</div>

> [@hypergamer7391](#):
>
> unabhängige website

Wenn Du damit eine Datei im Dateisystem LittleFS des ESP32 meinst, kann sich diese Seite Daten beispielsweise im JSON-Format holen.

Im Programm:

> buff += ""C180":["";  
> buff += kw180; // Variable mit den Daten  
> buff += ""],";

html-Datei JavaScript:

> document.getElementById("kw180").innerHTML=obj.C180+" KWh";

html-Datei body:

> \<td\>Bezug gesamt: &nbsp;&nbsp;&nbsp;\</td\>\<span id="kw180"\>\</span\>\</td\>

Anzeige im Browser:

![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/8/2/6820180cb7ddefe9733e954a58c84c515a3d39e2.png)

Nur damit Du eine grobe Vorstellung hast 🙂

---

<div class="post-metadata">

**Author:** ![Tommy56](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tommy56/32/232943_2.png) [@Tommy56](https://forum.arduino.cc/u/Tommy56)\
**Post date:** [February 2, 2025, 6:16pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/13 "2025-02-02T18:16:50Z")

</div>

Ich habe in der Regel nicht mal JSON verwendet, sondern Name/Wert-Paare mit ; getrennt. Dabei die Namen so wie die ID des HTML-Zielfeldes gewählt.

```arduino
feld1=325;feld2="Hallo";

```

Da kannst Du im Javascript den String am ; trennen und das in ein Array schieben und in einer Schleife über das Array die Felder füllen;

Da die Länge der Antwort bekannt ist, kann man mit String.reserve(Länge) auch das Fragmentierungsproblem umgehen oder es gleich mit snprintf bauen..

Gruß Tommy

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 1, 2025, 6:17pm UTC](https://forum.arduino.cc/t/esp32-html-script/1349680/14 "2025-08-01T18:17:16Z")

</div>

Closed on August 1, 2025, 6:17pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
