#include <WiFi.h>
#include <WebServer.h>
const char *ssid = "SSID";
const char *pass = "12345679";
WebServer myserver (80); // Port webserver
void setup() {
WiFi.begin(ssid, pass); // Kết nối đến AP với ssid và pass
while(WiFi.status() != WL_CONNECTED); // Kiểm tra kết nối wifi
myserver.on("/", handle_connect); // Phương thức on của webserver
myserver.on("/hello", handle_hello);
myserver.begin(); //Bật dau webserver
}
void loop() {
myserver.handleClient();
}
String html ="<p style=\"text-align: center;\">ESP32 WEBSERVER</p>"
"<p style=\"text-align:center;\">STA-MODE</p>"
"<p style=\"text-align: center;\">Lập trình giao tiếp thiết bị</p>"
"<p></p>";
void handle_connect(){
Serial.println("HTTP Request");
myserver.send(200, "text/html",html);
}
void handle_hello(){
Serial.println("HTTP Request");
myserver.send(200, "text/plain", "Hello Deviot");
}