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.
76 lines
1.8 KiB
76 lines
1.8 KiB
#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");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|