main.ino

Arduino (C++) · 32 lines

#include <WiFi.h>
#include <WebServer.h>

// Replace these with your Wi-Fi network credentials
const char* ssid = "xxx";
const char* password = "xxx";

WebServer server(80);  // HTTP server on port 80

void handleRoot() {
  server.send(200, "text/plain", "Hello world");
}

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }

  // Configure the only route: "/"
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
}