update instructions
This commit is contained in:
@@ -12,3 +12,22 @@ Store WiFi secrets in a secrets.h like this:
|
|||||||
#define SSID "your-ssid"
|
#define SSID "your-ssid"
|
||||||
#define PASSWORD "your-password"
|
#define PASSWORD "your-password"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Circuit
|
||||||
|
|
||||||
|
Circuit:
|
||||||
|
|
||||||
|
- LED attached to pin 13 (optional)
|
||||||
|
- IR Transmitter attached to pin 4 (connect to 5v or 3v3)
|
||||||
|
- SD-Module to load HTML and CSS from SD-card
|
||||||
|
|
||||||
|
Connect the SD card to the following pins:
|
||||||
|
|
||||||
|
SD Card | ESP32
|
||||||
|
------- | -----
|
||||||
|
3v3 | 3.3V
|
||||||
|
CS | 5
|
||||||
|
MOSI | 23
|
||||||
|
CLK | 18
|
||||||
|
MISO | 19
|
||||||
|
GND | GND
|
||||||
|
|||||||
@@ -14,19 +14,20 @@
|
|||||||
|
|
||||||
|
|
||||||
Circuit:
|
Circuit:
|
||||||
* LED attached to pin 13 (optional)
|
- LED attached to pin 13 (optional)
|
||||||
* IR Transmitter attached to pin 4 (connect to 5v or 3v3)
|
- IR Transmitter attached to pin 4 (connect to 5v or 3v3)
|
||||||
* SD-Module to load HTML and CSS from SD-card
|
- SD-Module to load HTML and CSS from SD-card
|
||||||
*
|
|
||||||
* Connect the SD card to the following pins:
|
Connect the SD card to the following pins:
|
||||||
*
|
|
||||||
* SD Card | ESP32
|
SD Card | ESP32
|
||||||
* 3v3 3.3V
|
------- | -----
|
||||||
* CS 5
|
3v3 | 3.3V
|
||||||
* MOSI 23
|
CS | 5
|
||||||
* CLK 18
|
MOSI | 23
|
||||||
* MISO 19
|
CLK | 18
|
||||||
* GND GND
|
MISO | 19
|
||||||
|
GND | GND
|
||||||
|
|
||||||
developed for the ESP32vn IoT Uni board 2024
|
developed for the ESP32vn IoT Uni board 2024
|
||||||
*/
|
*/
|
||||||
@@ -41,30 +42,37 @@
|
|||||||
|
|
||||||
WiFiServer server(80);
|
WiFiServer server(80);
|
||||||
|
|
||||||
|
|
||||||
/**** SD-Card Functions ****/
|
/**** SD-Card Functions ****/
|
||||||
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||||
|
{
|
||||||
Serial.printf("Listing directory: %s\n", dirname);
|
Serial.printf("Listing directory: %s\n", dirname);
|
||||||
|
|
||||||
File root = fs.open(dirname);
|
File root = fs.open(dirname);
|
||||||
if(!root){
|
if (!root)
|
||||||
|
{
|
||||||
Serial.println("Failed to open directory");
|
Serial.println("Failed to open directory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!root.isDirectory()){
|
if (!root.isDirectory())
|
||||||
|
{
|
||||||
Serial.println("Not a directory");
|
Serial.println("Not a directory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = root.openNextFile();
|
File file = root.openNextFile();
|
||||||
while(file){
|
while (file)
|
||||||
if(file.isDirectory()){
|
{
|
||||||
|
if (file.isDirectory())
|
||||||
|
{
|
||||||
Serial.print(" DIR : ");
|
Serial.print(" DIR : ");
|
||||||
Serial.println(file.name());
|
Serial.println(file.name());
|
||||||
if(levels){
|
if (levels)
|
||||||
listDir(fs, file.path(), levels -1);
|
{
|
||||||
|
listDir(fs, file.path(), levels - 1);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.print(" FILE: ");
|
Serial.print(" FILE: ");
|
||||||
Serial.print(file.name());
|
Serial.print(file.name());
|
||||||
Serial.print(" SIZE: ");
|
Serial.print(" SIZE: ");
|
||||||
@@ -74,35 +82,42 @@ void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readFile(fs::FS &fs, const char * path){
|
void readFile(fs::FS &fs, const char *path)
|
||||||
|
{
|
||||||
Serial.printf("Reading file: %s\n", path);
|
Serial.printf("Reading file: %s\n", path);
|
||||||
|
|
||||||
File file = fs.open(path);
|
File file = fs.open(path);
|
||||||
if(!file){
|
if (!file)
|
||||||
|
{
|
||||||
Serial.println("Failed to open file for reading");
|
Serial.println("Failed to open file for reading");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("Read from file: ");
|
Serial.print("Read from file: ");
|
||||||
while(file.available()){
|
while (file.available())
|
||||||
|
{
|
||||||
Serial.write(file.read());
|
Serial.write(file.read());
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testFileIO(fs::FS &fs, const char * path){
|
void testFileIO(fs::FS &fs, const char *path)
|
||||||
|
{
|
||||||
File file = fs.open(path);
|
File file = fs.open(path);
|
||||||
static uint8_t buf[512];
|
static uint8_t buf[512];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
uint32_t start = millis();
|
uint32_t start = millis();
|
||||||
uint32_t end = start;
|
uint32_t end = start;
|
||||||
if(file){
|
if (file)
|
||||||
|
{
|
||||||
len = file.size();
|
len = file.size();
|
||||||
size_t flen = len;
|
size_t flen = len;
|
||||||
start = millis();
|
start = millis();
|
||||||
while(len){
|
while (len)
|
||||||
|
{
|
||||||
size_t toRead = len;
|
size_t toRead = len;
|
||||||
if(toRead > 512){
|
if (toRead > 512)
|
||||||
|
{
|
||||||
toRead = 512;
|
toRead = 512;
|
||||||
}
|
}
|
||||||
file.read(buf, toRead);
|
file.read(buf, toRead);
|
||||||
@@ -111,20 +126,23 @@ void testFileIO(fs::FS &fs, const char * path){
|
|||||||
end = millis() - start;
|
end = millis() - start;
|
||||||
Serial.printf("%u bytes read for %u ms\n", flen, end);
|
Serial.printf("%u bytes read for %u ms\n", flen, end);
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.println("Failed to open file for reading");
|
Serial.println("Failed to open file for reading");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
file = fs.open(path, FILE_WRITE);
|
file = fs.open(path, FILE_WRITE);
|
||||||
if(!file){
|
if (!file)
|
||||||
|
{
|
||||||
Serial.println("Failed to open file for writing");
|
Serial.println("Failed to open file for writing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
start = millis();
|
start = millis();
|
||||||
for(i=0; i<2048; i++){
|
for (i = 0; i < 2048; i++)
|
||||||
|
{
|
||||||
file.write(buf, 512);
|
file.write(buf, 512);
|
||||||
}
|
}
|
||||||
end = millis() - start;
|
end = millis() - start;
|
||||||
@@ -141,7 +159,8 @@ void sendButton(int command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ============ Setup ============ */
|
/* ============ Setup ============ */
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
pinMode(LED_PIN, OUTPUT); // set the LED pin mode
|
pinMode(LED_PIN, OUTPUT); // set the LED pin mode
|
||||||
@@ -149,25 +168,34 @@ void setup() {
|
|||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
/* ============ SD-Card Setup ============ */
|
/* ============ SD-Card Setup ============ */
|
||||||
if(!SD.begin()){
|
if (!SD.begin())
|
||||||
|
{
|
||||||
Serial.println("Card Mount Failed");
|
Serial.println("Card Mount Failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint8_t cardType = SD.cardType();
|
uint8_t cardType = SD.cardType();
|
||||||
|
|
||||||
if(cardType == CARD_NONE){
|
if (cardType == CARD_NONE)
|
||||||
|
{
|
||||||
Serial.println("No SD card attached");
|
Serial.println("No SD card attached");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("SD Card Type: ");
|
Serial.print("SD Card Type: ");
|
||||||
if(cardType == CARD_MMC){
|
if (cardType == CARD_MMC)
|
||||||
|
{
|
||||||
Serial.println("MMC");
|
Serial.println("MMC");
|
||||||
} else if(cardType == CARD_SD){
|
}
|
||||||
|
else if (cardType == CARD_SD)
|
||||||
|
{
|
||||||
Serial.println("SDSC");
|
Serial.println("SDSC");
|
||||||
} else if(cardType == CARD_SDHC){
|
}
|
||||||
|
else if (cardType == CARD_SDHC)
|
||||||
|
{
|
||||||
Serial.println("SDHC");
|
Serial.println("SDHC");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.println("UNKNOWN");
|
Serial.println("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +207,6 @@ void setup() {
|
|||||||
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
|
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
|
||||||
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
|
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
|
||||||
|
|
||||||
|
|
||||||
/* ============ IR Setup ============ */
|
/* ============ IR Setup ============ */
|
||||||
IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
|
IrSender.begin(IR_SEND_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
|
||||||
Serial.println();
|
Serial.println();
|
||||||
@@ -197,7 +224,8 @@ void setup() {
|
|||||||
|
|
||||||
WiFi.begin(SSID, PASSWORD);
|
WiFi.begin(SSID, PASSWORD);
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
@@ -210,21 +238,27 @@ void setup() {
|
|||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
WiFiClient client = server.available(); // listen for incoming clients
|
WiFiClient client = server.available(); // listen for incoming clients
|
||||||
|
|
||||||
if (client) { // if you get a client,
|
if (client)
|
||||||
|
{ // if you get a client,
|
||||||
Serial.println("New Client."); // print a message out the serial port
|
Serial.println("New Client."); // print a message out the serial port
|
||||||
String currentLine = ""; // make a String to hold incoming data from the client
|
String currentLine = ""; // make a String to hold incoming data from the client
|
||||||
while (client.connected()) { // loop while the client's connected
|
while (client.connected())
|
||||||
if (client.available()) { // if there's bytes to read from the client,
|
{ // loop while the client's connected
|
||||||
|
if (client.available())
|
||||||
|
{ // if there's bytes to read from the client,
|
||||||
char c = client.read(); // read a byte, then
|
char c = client.read(); // read a byte, then
|
||||||
Serial.write(c); // print it out the serial monitor
|
Serial.write(c); // print it out the serial monitor
|
||||||
if (c == '\n') { // if the byte is a newline character
|
if (c == '\n')
|
||||||
|
{ // if the byte is a newline character
|
||||||
|
|
||||||
// if the current line is blank, you got two newline characters in a row.
|
// if the current line is blank, you got two newline characters in a row.
|
||||||
// that's the end of the client HTTP request, so send a response:
|
// that's the end of the client HTTP request, so send a response:
|
||||||
if (currentLine.length() == 0) {
|
if (currentLine.length() == 0)
|
||||||
|
{
|
||||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||||
// and a content-type so the client knows what's coming, then a blank line:
|
// and a content-type so the client knows what's coming, then a blank line:
|
||||||
client.println("HTTP/1.1 200 OK");
|
client.println("HTTP/1.1 200 OK");
|
||||||
@@ -239,39 +273,52 @@ void loop() {
|
|||||||
client.println();
|
client.println();
|
||||||
// break out of the while loop:
|
// break out of the while loop:
|
||||||
break;
|
break;
|
||||||
} else { // if you got a newline, then clear currentLine:
|
}
|
||||||
|
else
|
||||||
|
{ // if you got a newline, then clear currentLine:
|
||||||
currentLine = "";
|
currentLine = "";
|
||||||
}
|
}
|
||||||
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
}
|
||||||
|
else if (c != '\r')
|
||||||
|
{ // if you got anything else but a carriage return character,
|
||||||
currentLine += c; // add it to the end of the currentLine
|
currentLine += c; // add it to the end of the currentLine
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if the client request was "GET /H" or "GET /L":
|
// Check to see if the client request was "GET /H" or "GET /L":
|
||||||
if (currentLine.endsWith("GET /H")) {
|
if (currentLine.endsWith("GET /H"))
|
||||||
|
{
|
||||||
digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on
|
digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /L")) {
|
if (currentLine.endsWith("GET /L"))
|
||||||
|
{
|
||||||
digitalWrite(LED_PIN, LOW); // GET /L turns the LED off
|
digitalWrite(LED_PIN, LOW); // GET /L turns the LED off
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /power")) {
|
if (currentLine.endsWith("GET /power"))
|
||||||
|
{
|
||||||
sendButton(POWER);
|
sendButton(POWER);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /play")) {
|
if (currentLine.endsWith("GET /play"))
|
||||||
|
{
|
||||||
sendButton(PLAY);
|
sendButton(PLAY);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /pause")) {
|
if (currentLine.endsWith("GET /pause"))
|
||||||
|
{
|
||||||
sendButton(PAUSE);
|
sendButton(PAUSE);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /stop")) {
|
if (currentLine.endsWith("GET /stop"))
|
||||||
|
{
|
||||||
sendButton(STOP);
|
sendButton(STOP);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /prev")) {
|
if (currentLine.endsWith("GET /prev"))
|
||||||
|
{
|
||||||
sendButton(PREV);
|
sendButton(PREV);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("GET /next")) {
|
if (currentLine.endsWith("GET /next"))
|
||||||
|
{
|
||||||
sendButton(NEXT);
|
sendButton(NEXT);
|
||||||
}
|
}
|
||||||
if (currentLine.endsWith("POST /api/control-deck")) {
|
if (currentLine.endsWith("POST /api/control-deck"))
|
||||||
|
{
|
||||||
|
|
||||||
Serial.println("POST");
|
Serial.println("POST");
|
||||||
char c = client.read();
|
char c = client.read();
|
||||||
@@ -284,5 +331,3 @@ void loop() {
|
|||||||
Serial.println("Client Disconnected.");
|
Serial.println("Client Disconnected.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user