Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- const char* ssid = "your_SSID";
- const char* password = "your_PASSWORD";
- ESP8266WebServer server(80);
- int valoreVariabile = 42;
- // Definisci il contenuto HTML come una stringa
- const char* htmlTemplate = R"(
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>ESP8266 Web Server</title>
- </head>
- <body>
- <h1>Valore della variabile: %VALORE_VARIABILE%</h1>
- </body>
- </html>
- )";
- void setup() {
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- // Attendi connessione WiFi
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- Serial.println("Connected to WiFi!");
- // Stampa l'indirizzo IP
- Serial.print("Indirizzo IP del server: ");
- Serial.println(WiFi.localIP());
- // Imposta le route
- server.on("/", handleRoot);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop() {
- server.handleClient();
- }
- void handleRoot() {
- String htmlContent = String(htmlTemplate);
- htmlContent.replace("%VALORE_VARIABILE%", String(valoreVariabile));
- server.send(200, "text/html", htmlContent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement