Skip to content

Instantly share code, notes, and snippets.

@brulint
Created July 11, 2026 23:31
Show Gist options
  • Select an option

  • Save brulint/b370e60c03f5f84c63a25b72c32579e6 to your computer and use it in GitHub Desktop.

Select an option

Save brulint/b370e60c03f5f84c63a25b72c32579e6 to your computer and use it in GitHub Desktop.
Simple webserver on ESP32
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);
void handleRoot() {
String html = "<!DOCTYPE html>\n";
html += "<html>\n";
html += "<head>\n";
html += "<title>Server ESP32</title>\n";
html += "<meta charset=\"UTF-8\">\n";
html += "</head>\n";
html += "<body>\n";
html += "<h1>Hello world!</h1>\n";
html += "</body>\n";
html += "</html>";
server.send(200, "text/html", html);
}
void handleNotFound() {
server.send(404, "text/plain", "File Not Found");
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(100);
WiFi.begin("SSID", "p4sswOrd");
Serial.print("Connecting to WiFi... ");
while (WiFi.status() != WL_CONNECTED) delay(500);
Serial.println("Ok.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment