Browse Source

FS esp32

master
Jakub Škrabánek 1 week ago
parent
commit
31464cb5af
  1. 18
      21_esp_html_fs/data/fotka.html
  2. BIN
      21_esp_html_fs/data/logo.png
  3. 26
      21_esp_html_fs/src/main.cpp

18
21_esp_html_fs/data/fotka.html

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<nav>
<a href="/">Domů</a>
<a href="/fotka">Ukázka fotky</a>
</nav>
<h1>Fotka na druhé stránce</h1>
<img src="/logo.png" alt="Naše logo uložené v ESP32">
</body>
</html>

BIN
21_esp_html_fs/data/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

26
21_esp_html_fs/src/main.cpp

@ -39,6 +39,29 @@ void handleRoot() {
if (teplota > 30) teplota = 15; if (teplota > 30) teplota = 15;
} }
void handleFotka() {
File file = LittleFS.open("/fotka.html","r");
if(!file) {
server.send(500,"text/plain","Chyba serveru 500");
return;
}
server.streamFile(file,"text/html");
file.close();
}
void handleLogo() {
File file = LittleFS.open("/logo.png","r");
if(!file) {
server.send(500,"text/plain","Chyba serveru 500");
return;
}
server.streamFile(file,"image/png");
file.close();
}
void handleNotFound(){
server.send(404,"text/plain","404 - Nic nenalezeno, mňo máš smůlu ☺");
}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
//Inicializaceš fylesystému LittleFS //Inicializaceš fylesystému LittleFS
@ -61,6 +84,9 @@ void setup() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
server.on("/",handleRoot); server.on("/",handleRoot);
server.on("/fotka",handleFotka);
server.on("/logo.png",handleLogo);
server.onNotFound(handleNotFound);
server.begin(); server.begin();
Serial.println("HTTP server běží"); Serial.println("HTTP server běží");

Loading…
Cancel
Save