diff --git a/04_WiFi_connect/04_WiFi_connect.ino b/04_WiFi_connect/04_WiFi_connect.ino index 061cbf8..c7e0525 100644 --- a/04_WiFi_connect/04_WiFi_connect.ino +++ b/04_WiFi_connect/04_WiFi_connect.ino @@ -29,4 +29,5 @@ void setup() { Serial.println(WiFi.getHostname()); } void loop(){ + } \ No newline at end of file diff --git a/05_simple_http/05_simple_http.ino b/05_simple_http/05_simple_http.ino new file mode 100644 index 0000000..4b60486 --- /dev/null +++ b/05_simple_http/05_simple_http.ino @@ -0,0 +1,76 @@ +#include + +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(""); + client.println(""); + client.println("Hello World"); + client.println(""); + client.println("

Hello World from ESP32

"); + client.println(""); + client.println(""); + break; + } else { + currentLine = ""; + } + } else if (c != '\r'){ + currentLine += c; + } + } + } + delay(1); + client.stop(); + Serial.println("Klient odpojen"); + } +} + + + +