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.
69 lines
1.5 KiB
69 lines
1.5 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("Webovy server spusten");
|
|
}
|
|
|
|
void loop(){
|
|
server.handleClient(); //Obsluha klientů
|
|
}
|
|
|
|
//"metoda" pro výpis stránky pro "požadavek"
|
|
void handleRoot() {
|
|
String html = "<!DOCTYPE html><html><head>";
|
|
html += "<title>ESP32 LED</title>";
|
|
html += "</head><body>";
|
|
html += "<h1> Ovladani LED </h1>";
|
|
html += "<p> Stav LED: ";
|
|
if(digitalRead(LED_BUILTIN) == HIGH){
|
|
html += "ON";
|
|
} else {
|
|
html += "OFF";
|
|
}
|
|
html += "</p>";
|
|
html += "<a href='/on'>Zapnout</a> <br>";
|
|
html += "<a href='/off'>Vypnout</a>";
|
|
html += "</body></html>";
|
|
server.send(200, "text/html",html);
|
|
}
|
|
|
|
void handleOn() {
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
server.sendHeader("Location", "/");
|
|
server.send(302, "text/plain", "");
|
|
}
|
|
|
|
void handleOff() {
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
server.sendHeader("Location", "/");
|
|
server.send(302, "text/plain", "");
|
|
}
|
|
|
|
void handleNotFound() {
|
|
server.send(404, "text/plain", "Stranka nenalezena");
|
|
}
|
|
|
|
|