Еспшка раз в 5 минут просыпается и делает фотки на SD карту. + wifi сканирует и тоже на карту складывает в файлики список видимых wifi.
Сейчас пытаюсь научить её выгребать всё содержимое SD карты вместе с каталогами на FTP сервер (компутер).
Пока получилось объединить два примера из ибиблиотек:
SDMMC и ESP32FTP.
SDMMC делает листинг каталогов и файлов. Когда добирается до файлов и должен выводить их список с размерами, то тут добавил работу бибилотеки ESP32FTP. Выгрузку файлов на фтп.
на карте есть каталоги:
System Volume Information\IndexerVolumeGuid (файл)
System Volume Information\WPSettings.dat (файл)
2021\03\30\pictures\*.jpg (30 файлов по 18-40Кб)
2021\03\30\wifi\*.txt (30 файлов по 1Кб)
2021\03\31\pictures\*.jpg (30 файлов по 18-40Кб)
2021\03\31\wifi\*.txt (30 файлов по 1Кб)
Первые два файла заливаются на фтп и удаляются с карты.
Дальше идёт крэш...
15:32:42.065 -> SD_MMC Card Type: SDSC
15:32:42.722 -> SD_MMC Card Size: 1886MB
15:32:42.722 -> Listing directory: /
15:32:42.722 -> DIR : /System Volume Information
15:32:42.722 -> Listing directory: /System Volume Information
15:32:42.722 -> FILE: /System Volume Information/WPSettings.dat SIZE: 1024
15:32:43.003 -> Reading file: 4?⸮?/
15:32:43.003 -> Read from file: Deleting file: /System Volume Information/WPSettings.dat
15:32:43.143 -> File deleted
15:32:43.143 -> FILE: /System Volume Information/IndexerVolumeGuid SIZE: 1024
15:32:43.284 -> Reading file: xB⸮?/
15:32:43.331 -> Read from file: Deleting file: /System Volume Information/IndexerVolumeGuid
15:32:43.331 -> File deleted
15:32:43.331 -> DIR : /2021
15:32:43.331 -> Listing directory: /2021
15:32:43.331 -> DIR : /2021/03
15:32:43.378 -> Listing directory: /2021/03
15:32:43.378 -> DIR : /2021/03/30
15:32:43.378 -> Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception)
15:32:43.518 -> Debug exception reason: Stack canary watchpoint triggered (loopTask)
15:32:43.518 -> Core 1 register dump:
15:32:43.518 -> PC : 0x400da138 PS : 0x00060036 A0 : 0x800df925 A1 : 0x3ffafdb0
15:32:43.518 -> A2 : 0x3ffb80c0 A3 : 0x3ffb00c0 A4 : 0x3f4001c5 A5 : 0x3ffb0210
15:32:43.518 -> A6 : 0x3ffb0190 A7 : 0x00000008 A8 : 0x800da136 A9 : 0x3ffafd90
15:32:43.518 -> A10 : 0x3ff9c50f A11 : 0x00060023 A12 : 0x00060020 A13 : 0x00000000
15:32:43.518 -> A14 : 0x00000000 A15 : 0x00000000 SAR : 0x00000019 EXCCAUSE: 0x00000001
15:32:43.518 -> EXCVADDR: 0x00000000 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
15:32:43.518 ->
15:32:43.518 -> ELF file SHA256: 0000000000000000
15:32:43.518 ->
15:32:43.518 -> Backtrace: 0x400da138:0x3ffafdb0 0x400df922:0x3ffb00c0 0x400df95a:0x3ffb0150 0x400d4036:0x3ffb0190 0x400d13b2:0x3ffb0230 0x400d147e:0x3ffb0980 0x400d147e:0x3ffb10d0 0x400d147e:0x3ffb1820 0x400d174f:0x3ffb1f70 0x400d4736:0x3ffb1fb0 0x4008a4be:0x3ffb1fd0
15:32:43.518 ->
15:32:43.518 -> Rebooting...
#include "FS.h"
#include "SD_MMC.h"
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP32_FTPClient.h>
#include "Secrets.h"
//!!DONT FORGET TO UPDATE Secrets.h with your WIFI Credentials!!
char ftp_server[] = "192.168.100.666";
char ftp_user[] = "esp";
char ftp_pass[] = "esp";
// you can pass a FTP timeout and debbug mode on the last 2 arguments
ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 0); // Disable Debug to increase Tx Speed
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
readAndSendBigBinFile(SD_MMC, file.name(), ftp);
deleteFile(SD_MMC, file.name());
}
file = root.openNextFile();
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\n", path);
if(fs.remove(path)){
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
void readAndSendBigBinFile(fs::FS& fs, const char* path, ESP32_FTPClient ftpClient) {
ftpClient.InitFile("Type I");
ftpClient.NewFile(path);
String fullPath = "/";
fullPath.concat(path);
Serial.printf("Reading file: %s\n", fullPath);
File file = fs.open(fullPath);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
// Create and fill a buffer
unsigned char buf[1024];
int readVal = file.read(buf, sizeof(buf));
ftpClient.WriteData(buf,sizeof(buf));
}
ftpClient.CloseFile();
file.close();
}
void setup(){
Serial.begin(115200);
WiFi.begin( WIFI_SSID, WIFI_PASS );
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if(!SD_MMC.begin()){
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD_MMC card attached");
return;
}
Serial.print("SD_MMC Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
ftp.OpenConnection();
ftp.ChangeWorkDir("esp");
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
listDir(SD_MMC, "/", 4);
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop(){
}
(000198)31.03.2021 15:32:42 - (not logged in) (192.168.100.91)> Connected on port 21, sending welcome message...
(000198)31.03.2021 15:32:42 - (not logged in) (192.168.100.91)> 220-FileZilla Server 0.9.60 beta
(000198)31.03.2021 15:32:42 - (not logged in) (192.168.100.91)> USER esp
(000198)31.03.2021 15:32:42 - (not logged in) (192.168.100.91)> 331 Password required for esp
(000198)31.03.2021 15:32:42 - (not logged in) (192.168.100.91)> PASS ***
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 230 Logged on
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> SYST
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 215 UNIX emulated by FileZilla
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> CWD esp
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 250 CWD successful. "/esp" is current directory.
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> Type I
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 200 Type set to I
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> PASV
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 227 Entering Passive Mode (192,168,100,35,204,6)
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> STOR /System Volume Information/WPSettings.dat
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 150 Opening data channel for file upload to server of "/System Volume Information/WPSettings.dat"
(000198)31.03.2021 15:32:42 - esp (192.168.100.91)> 226 Successfully transferred "/System Volume Information/WPSettings.dat"
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> Type I
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> 200 Type set to I
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> PASV
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> 227 Entering Passive Mode (192,168,100,35,230,19)
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> STOR /System Volume Information/IndexerVolumeGuid
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> 150 Opening data channel for file upload to server of "/System Volume Information/IndexerVolumeGuid"
(000198)31.03.2021 15:32:43 - esp (192.168.100.91)> 226 Successfully transferred "/System Volume Information/IndexerVolumeGuid"
(000199)31.03.2021 15:32:45 - (not logged in) (192.168.100.91)> Connected on port 21, sending welcome message...
(000199)31.03.2021 15:32:45 - (not logged in) (192.168.100.91)> 220-FileZilla Server 0.9.60 beta
(000199)31.03.2021 15:32:45 - (not logged in) (192.168.100.91)> USER esp
(000199)31.03.2021 15:32:45 - (not logged in) (192.168.100.91)> 331 Password required for esp
(000199)31.03.2021 15:32:45 - (not logged in) (192.168.100.91)> PASS ***
(000199)31.03.2021 15:32:45 - esp (192.168.100.91)> 230 Logged on
(000199)31.03.2021 15:32:45 - esp (192.168.100.91)> SYST
(000199)31.03.2021 15:32:45 - esp (192.168.100.91)> 215 UNIX emulated by FileZilla
(000199)31.03.2021 15:32:45 - esp (192.168.100.91)> CWD esp
(000199)31.03.2021 15:32:45 - esp (192.168.100.91)> 250 CWD successful. "/esp" is current directory.
(000199)31.03.2021 15:32:47 - esp (192.168.100.91)> disconnected.
(000200)31.03.2021 15:32:48 - (not logged in) (192.168.100.91)> Connected on port 21, sending welcome message...
(000200)31.03.2021 15:32:48 - (not logged in) (192.168.100.91)> 220-FileZilla Server 0.9.60 beta
(000200)31.03.2021 15:32:48 - (not logged in) (192.168.100.91)> USER esp
(000200)31.03.2021 15:32:48 - (not logged in) (192.168.100.91)> 331 Password required for esp
(000200)31.03.2021 15:32:48 - (not logged in) (192.168.100.91)> PASS ***
(000200)31.03.2021 15:32:48 - esp (192.168.100.91)> 230 Logged on
(000200)31.03.2021 15:32:48 - esp (192.168.100.91)> SYST
(000200)31.03.2021 15:32:48 - esp (192.168.100.91)> 215 UNIX emulated by FileZilla
(000200)31.03.2021 15:32:48 - esp (192.168.100.91)> CWD esp
(000200)31.03.2021 15:32:48 - esp (192.168.100.91)> 250 CWD successful. "/esp" is current directory.
(000200)31.03.2021 15:32:49 - esp (192.168.100.91)> disconnected.
(000201)31.03.2021 15:32:49 - (not logged in) (192.168.100.91)> Connected on port 21, sending welcome message...
(000201)31.03.2021 15:32:49 - (not logged in) (192.168.100.91)> 220-FileZilla Server 0.9.60 beta
(000201)31.03.2021 15:32:50 - (not logged in) (192.168.100.91)> USER esp
(000201)31.03.2021 15:32:50 - (not logged in) (192.168.100.91)> 331 Password required for esp
(000201)31.03.2021 15:32:50 - (not logged in) (192.168.100.91)> PASS ***
(000201)31.03.2021 15:32:50 - esp (192.168.100.91)> 230 Logged on
(000201)31.03.2021 15:32:50 - esp (192.168.100.91)> SYST
(000201)31.03.2021 15:32:50 - esp (192.168.100.91)> 215 UNIX emulated by FileZilla
(000201)31.03.2021 15:32:50 - esp (192.168.100.91)> CWD esp
(000201)31.03.2021 15:32:50 - esp (192.168.100.91)> 250 CWD successful. "/esp" is current directory.
(000202)31.03.2021 15:32:51 - (not logged in) (192.168.100.91)> Connected on port 21, sending welcome message...
(000202)31.03.2021 15:32:51 - (not logged in) (192.168.100.91)> 220-FileZilla Server 0.9.60 beta
(000201)31.03.2021 15:32:52 - esp (192.168.100.91)> disconnected.
Без ошибок даёт выгружать файлы из каталогов глубиной не более 1-го.
../pictures/*.jpg
../wifi/*.txt
Глубже уже вылетает. Не стал дальше разбираться. Оставил так.