2 changed files with 77 additions and 0 deletions
@ -0,0 +1,76 @@ |
|||
#include <WiFi.h> |
|||
|
|||
const char* ssid = "tksteti"; |
|||
const char* password = "ProsimTeNevim"; |
|||
|
|||
const char* deviceName = "ESP-VasePrijmeni"; |
|||
|
|||
WiFiServer server(80); |
|||
|
|||
void setup() { |
|||
Serial.begin(115200); //nastaveni Serioveho monitoru
|
|||
delay(10); |
|||
|
|||
WiFi.setHostname(deviceName); |
|||
|
|||
Serial.println(); |
|||
Serial.print("Pripojuji se k WiFi: "); |
|||
Serial.println(); |
|||
|
|||
WiFi.begin(ssid,password); //začátek připojování
|
|||
while(WiFi.status() != WL_CONNECTED) { //připojování
|
|||
delay(500); |
|||
Serial.print("."); |
|||
} |
|||
|
|||
Serial.println(); |
|||
Serial.println("WiFi připojeno"); // po připojení
|
|||
Serial.print("IP adresa: "); |
|||
Serial.println(WiFi.localIP()); //zobrazení IP adresy
|
|||
Serial.print("Hostname: "); |
|||
Serial.println(WiFi.getHostname()); |
|||
|
|||
//spusteni serveru
|
|||
server.begin(); |
|||
} |
|||
void loop(){ |
|||
WiFiClient client = server.available(); |
|||
if(client){ |
|||
Serial.println("Novy klient pripojen"); |
|||
String currentLine = ""; |
|||
|
|||
while(client.connected()) { |
|||
if (client.available()) { |
|||
char c = client.read(); |
|||
Serial.write(c); |
|||
|
|||
if (c == '\n'){ |
|||
if(currentLine.length() == 0) { |
|||
client.println("HTTP/1.1 200 OK"); |
|||
client.println("Content-Type: text/html"); |
|||
client.println(); //odelení hlavičky a html
|
|||
client.println("<!DOCTYPE html>"); |
|||
client.println("<html>"); |
|||
client.println("<head><title>Hello World</title></head>"); |
|||
client.println("<body>"); |
|||
client.println("<h1>Hello World from ESP32</h1>"); |
|||
client.println("</body>"); |
|||
client.println("</html>"); |
|||
break; |
|||
} else { |
|||
currentLine = ""; |
|||
} |
|||
} else if (c != '\r'){ |
|||
currentLine += c; |
|||
} |
|||
} |
|||
} |
|||
delay(1); |
|||
client.stop(); |
|||
Serial.println("Klient odpojen"); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
Loading…
Reference in new issue