6 changed files with 166 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||
.pio |
|||
.vscode/.browse.c_cpp.db* |
|||
.vscode/c_cpp_properties.json |
|||
.vscode/launch.json |
|||
.vscode/ipch |
@ -0,0 +1,10 @@ |
|||
{ |
|||
// See http://go.microsoft.com/fwlink/?LinkId=827846 |
|||
// for the documentation about the extensions.json format |
|||
"recommendations": [ |
|||
"platformio.platformio-ide" |
|||
], |
|||
"unwantedRecommendations": [ |
|||
"ms-vscode.cpptools-extension-pack" |
|||
] |
|||
} |
@ -0,0 +1,22 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta http-equiv="refresh" content="5"> |
|||
<meta charset="UTF-8"> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|||
<title>Document</title> |
|||
</head> |
|||
<body> |
|||
<h1> Ovládání LED</h1> |
|||
|
|||
<h2>LED 1</h2> |
|||
<a href="/led1?state=on">ZAPNOUT</a> |
|||
<a href="/led1?state=off">VYPNOUT</a> |
|||
<div>stav: <span>STAVLED1</span></div> |
|||
|
|||
<h2>LED 2</h2> |
|||
<a href="/led2?state=on">ZAPNOUT</a> |
|||
<a href="/led2?state=off">VYPNOUT</a> |
|||
<div>stav: <span>STAVLED2</span></div> |
|||
</body> |
|||
</html> |
@ -0,0 +1,16 @@ |
|||
; PlatformIO Project Configuration File |
|||
; |
|||
; Build options: build flags, source filter |
|||
; Upload options: custom upload port, speed and extra flags |
|||
; Library options: dependencies, extra library storages |
|||
; Advanced options: extra scripting |
|||
; |
|||
; Please visit documentation for the other options and examples |
|||
; https://docs.platformio.org/page/projectconf.html |
|||
|
|||
[env:esp32dev] |
|||
platform = espressif32 |
|||
board = esp32dev |
|||
framework = arduino |
|||
monitor_speed = 115200 |
|||
board_build.filesystem = littlefs |
@ -0,0 +1,102 @@ |
|||
#include <Arduino.h> |
|||
#include <LittleFS.h> |
|||
#include <WiFi.h> |
|||
#include <WebServer.h> |
|||
|
|||
const char* ssid = "tksteti"; |
|||
const char* password = "ProsimTeNevim"; |
|||
WebServer server(80); |
|||
|
|||
const int ledPin1 = 2; |
|||
const int ledPin2 = 4; |
|||
bool ledState1 = false; |
|||
bool ledState2 = false; |
|||
|
|||
String loadHtml() { |
|||
File file = LittleFS.open("/index.html","r"); |
|||
if(!file) { |
|||
Serial.println("Chyba při otevírání /index.html"); |
|||
return "soubor nenalezen"; |
|||
} |
|||
String html = file.readString(); |
|||
file.close(); |
|||
//String(ledState1) převede bool na String)
|
|||
html.replace("STAVLED1", String(ledState1)); |
|||
html.replace("STAVLED2", ledState2 ? "ON" : "OFF"); |
|||
return html; |
|||
} |
|||
|
|||
void handleRoot(){ |
|||
server.send(200,"text/html",loadHtml()); |
|||
} |
|||
|
|||
void handleLED1() { |
|||
if(server.hasArg("state")) { |
|||
String state = server.arg("state"); |
|||
if(state == "on") { |
|||
ledState1 = true; |
|||
digitalWrite(ledPin1,HIGH); |
|||
} else { |
|||
ledState1 = false; |
|||
digitalWrite(ledPin1,LOW); |
|||
} |
|||
server.sendHeader("Location","/"); |
|||
server.send(302,"text/plain",""); |
|||
} else { |
|||
server.send(400,"BAD REQUEST"); |
|||
} |
|||
} |
|||
|
|||
void handleLED2() { |
|||
if(server.hasArg("state")) { |
|||
String state = server.arg("state"); |
|||
if(state == "on") { |
|||
ledState2 = true; |
|||
digitalWrite(ledPin2,HIGH); |
|||
} else { |
|||
ledState2 = false; |
|||
digitalWrite(ledPin2,LOW); |
|||
} |
|||
server.sendHeader("Location","/"); |
|||
server.send(302,"text/plain",""); |
|||
} else { |
|||
server.send(400,"BAD REQUEST"); |
|||
} |
|||
} |
|||
|
|||
void setup() { |
|||
Serial.begin(115200); |
|||
pinMode(ledPin1,OUTPUT); |
|||
pinMode(ledPin2,OUTPUT); |
|||
digitalWrite(ledPin1,LOW); |
|||
digitalWrite(ledPin2,LOW); |
|||
|
|||
WiFi.setHostname("ESP-Prijmeni"); |
|||
WiFi.begin(ssid,password); |
|||
while(WiFi.status() != WL_CONNECTED){ |
|||
delay(200); |
|||
Serial.print("."); |
|||
} |
|||
Serial.println("WiFi připojeno"); |
|||
Serial.print("IP adresa: "); |
|||
Serial.print(WiFi.localIP()); |
|||
|
|||
if(!LittleFS.begin()){ |
|||
Serial.println("Chyba při zavádění (mounting) LittleFS"); |
|||
return; |
|||
} |
|||
|
|||
server.on("/",handleRoot); |
|||
server.on("/led1",handleLED1); |
|||
server.on("/led2",handleLED2); |
|||
server.onNotFound([](){ |
|||
server.send(404,"text/plain","Stranka nenalezena"); |
|||
}); |
|||
|
|||
server.begin(); |
|||
Serial.println("HTTP Server spuštěn"); |
|||
} |
|||
|
|||
void loop() { |
|||
server.handleClient(); |
|||
} |
@ -0,0 +1,11 @@ |
|||
|
|||
This directory is intended for PlatformIO Test Runner and project tests. |
|||
|
|||
Unit Testing is a software testing method by which individual units of |
|||
source code, sets of one or more MCU program modules together with associated |
|||
control data, usage procedures, and operating procedures, are tested to |
|||
determine whether they are fit for use. Unit testing finds problems early |
|||
in the development cycle. |
|||
|
|||
More information about PlatformIO Unit Testing: |
|||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html |
Loading…
Reference in new issue