You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.1 KiB
53 lines
1.1 KiB
#include <WiFi.h>
|
|
#include <WebServer.h>
|
|
#define LED_BUILTIN 2
|
|
const char* ssid = "tksteti";
|
|
const char* password = "ProsimTeNevim";
|
|
WebServer server(80);
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
pinMode(LED_BUILTIN,OUTPUT);
|
|
|
|
WiFi.begin(ssid,password);
|
|
while(WiFi.status() != WL_CONNECTED) {
|
|
Serial.print(".");
|
|
delay(100);
|
|
}
|
|
Serial.println("Připojeno k WiFi");
|
|
Serial.print("IP Adresa:");
|
|
Serial.println(WiFi.localIP());
|
|
|
|
//jednotlivé odkazy
|
|
server.on("/", handleRoot);
|
|
server.on("/on", handleOn);
|
|
server.on("/off", handleOff);
|
|
server.onNotFound(handleNotFound);
|
|
|
|
server.begin();
|
|
Serial.println("Wwebovy server spusten");
|
|
}
|
|
|
|
void loop(){
|
|
server.handleClient(); //Obsluha klientů
|
|
}
|
|
|
|
//"metoda" pro výpis stránky pro "požadavek"
|
|
void handleRoot() {
|
|
server.send(200, "text/plain", "Vitej na webove strance tveho ESP32");
|
|
}
|
|
|
|
void handleOn() {
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
server.send(200, "text/plain", "LED zapnuta");
|
|
}
|
|
|
|
void handleOff() {
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
server.send(200, "text/plain", "LED vypnuta");
|
|
}
|
|
|
|
void handleNotFound() {
|
|
server.send(404, "text/plain", "Stranka nenalezena");
|
|
}
|
|
|
|
|