mirror of https://github.com/arendst/Tasmota.git
Update xdrv_98_filesystem.ino
This commit is contained in:
parent
2dd3065aff
commit
0a882f53ba
|
@ -17,17 +17,19 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
#ifdef USE_UFILESYS
|
||||||
this driver adds universal file system support for
|
/*********************************************************************************************\
|
||||||
ESP8266 (sd card or littlfs on > 1 M devices with special linker file e.g. eagle.flash.4m2m.ld)
|
This driver adds universal file system support for ESP8266 (sd card or littlfs on > 1 M devices
|
||||||
(makes no sense on 1M devices without sd card)
|
with special linker file e.g. eagle.flash.4m2m.ld) (makes no sense on 1M devices without sd card)
|
||||||
and
|
and ESP32 (sd card or little fs or sfatfile system).
|
||||||
ESP32 (sd card or little fs or sfatfile system)
|
|
||||||
the sd card chip select is the standard SPI_CS or when not found SDCARD_CS_PIN
|
The sd card chip select is the standard SDCARD_CS or when not found SDCARD_CS_PIN and initializes
|
||||||
initializes the FS System Pointer ufsp which can be used by all standard file system calls
|
the FS System Pointer ufsp which can be used by all standard file system calls.
|
||||||
the only specific call is ufs_fsinfo() which gets the total size (0) and free size (1)
|
|
||||||
a button is created in the setup section to show up the file directory to download and upload files
|
The only specific call is ufs_fsinfo() which gets the total size (0) and free size (1).
|
||||||
subdirectories are supported
|
|
||||||
|
A button is created in the setup section to show up the file directory to download and upload files
|
||||||
|
subdirectories are supported.
|
||||||
|
|
||||||
console calls :
|
console calls :
|
||||||
|
|
||||||
|
@ -36,32 +38,32 @@ ufstype get filesytem type 0=none 1=SD 2=Flashfile
|
||||||
ufssize total size in kB
|
ufssize total size in kB
|
||||||
ufsfree free size in kB
|
ufsfree free size in kB
|
||||||
|
|
||||||
driver enabled by
|
The driver enabled by #define USE_UFILESYS
|
||||||
|
\*********************************************************************************************/
|
||||||
#define USE_UFILESYS
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_UFILESYS
|
|
||||||
|
|
||||||
#define XDRV_98 98
|
#define XDRV_98 98
|
||||||
|
|
||||||
|
#ifndef SDCARD_CS_PIN
|
||||||
|
#define SDCARD_CS_PIN 4
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#include <SDFAT.h>
|
#include <SDFAT.h>
|
||||||
#endif
|
#endif // USE_SDCARD
|
||||||
#else
|
#endif // ESP8266
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
#include <LITTLEFS.h>
|
#include <LITTLEFS.h>
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#endif
|
#endif // USE_SDCARD
|
||||||
#include "FFat.h"
|
#include "FFat.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#endif
|
#endif // ESP32
|
||||||
|
|
||||||
#define UFS_FILE_WRITE "w"
|
#define UFS_FILE_WRITE "w"
|
||||||
#define UFS_FILE_READ "r"
|
#define UFS_FILE_READ "r"
|
||||||
|
@ -71,11 +73,6 @@ FS *ufsp;
|
||||||
char ufs_path[48];
|
char ufs_path[48];
|
||||||
File ufs_upload_file;
|
File ufs_upload_file;
|
||||||
|
|
||||||
|
|
||||||
#ifndef SDCARD_CS_PIN
|
|
||||||
#define SDCARD_CS_PIN 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 0 = none, 1 = SD, 2 = ffat, 3 = littlefs
|
// 0 = none, 1 = SD, 2 = ffat, 3 = littlefs
|
||||||
// spiffs should be obsolete
|
// spiffs should be obsolete
|
||||||
uint8_t ufs_type;
|
uint8_t ufs_type;
|
||||||
|
@ -92,19 +89,20 @@ void UFSInit(void) {
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
// if (TasmotaGlobal.spi_enabled) {
|
if (TasmotaGlobal.spi_enabled) {
|
||||||
if (1) {
|
// if (1) {
|
||||||
int8_t cs = SDCARD_CS_PIN;
|
int8_t cs = SDCARD_CS_PIN;
|
||||||
if (PinUsed(GPIO_SPI_CS)) {
|
if (PinUsed(GPIO_SDCARD_CS)) {
|
||||||
cs = Pin(GPIO_SPI_CS);
|
cs = Pin(GPIO_SDCARD_CS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SD.begin(cs)) {
|
if (SD.begin(cs)) {
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
ufsp = (FS*)&SD;
|
ufsp = (FS*)&SD;
|
||||||
#else
|
#endif // ESP8266
|
||||||
|
#ifdef ESP32
|
||||||
ufsp = &SD;
|
ufsp = &SD;
|
||||||
#endif
|
#endif // ESP32
|
||||||
ufs_type = UFS_TSDC;
|
ufs_type = UFS_TSDC;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +115,8 @@ void UFSInit(void) {
|
||||||
if (!LittleFS.begin()) {
|
if (!LittleFS.begin()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#endif // ESP8266
|
||||||
|
#ifdef ESP32
|
||||||
// try lfs first
|
// try lfs first
|
||||||
ufsp = &LITTLEFS;
|
ufsp = &LITTLEFS;
|
||||||
if (!LITTLEFS.begin(true)) {
|
if (!LITTLEFS.begin(true)) {
|
||||||
|
@ -129,33 +128,35 @@ void UFSInit(void) {
|
||||||
ufs_type = UFS_TFAT;
|
ufs_type = UFS_TFAT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif // ESP8266
|
#endif // ESP32
|
||||||
ufs_type = UFS_TLFS;
|
ufs_type = UFS_TLFS;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ufs_fsinfo(uint32_t sel) {
|
uint32_t ufs_fsinfo(uint32_t sel) {
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
FSInfo64 fsinfo;
|
FSInfo64 fsinfo;
|
||||||
#endif
|
#endif // ESP8266
|
||||||
|
|
||||||
switch (ufs_type) {
|
switch (ufs_type) {
|
||||||
case UFS_TSDC:
|
case UFS_TSDC:
|
||||||
#ifdef USE_SDCARD
|
#ifdef USE_SDCARD
|
||||||
#ifdef ESP32
|
#ifdef ESP8266
|
||||||
if (sel == 0) {
|
|
||||||
result = SD.totalBytes();
|
|
||||||
} else {
|
|
||||||
result = (SD.totalBytes() - SD.usedBytes());
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
ufsp->info64(fsinfo);
|
ufsp->info64(fsinfo);
|
||||||
if (sel == 0) {
|
if (sel == 0) {
|
||||||
result = fsinfo.totalBytes;
|
result = fsinfo.totalBytes;
|
||||||
} else {
|
} else {
|
||||||
result = (fsinfo.totalBytes - fsinfo.usedBytes);
|
result = (fsinfo.totalBytes - fsinfo.usedBytes);
|
||||||
}
|
}
|
||||||
|
#endif // ESP8266
|
||||||
|
#ifdef ESP32
|
||||||
|
if (sel == 0) {
|
||||||
|
result = SD.totalBytes();
|
||||||
|
} else {
|
||||||
|
result = (SD.totalBytes() - SD.usedBytes());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif //USE_SDCARD
|
#endif //USE_SDCARD
|
||||||
break;
|
break;
|
||||||
|
@ -168,13 +169,14 @@ FSInfo64 fsinfo;
|
||||||
} else {
|
} else {
|
||||||
result = (fsinfo.totalBytes - fsinfo.usedBytes);
|
result = (fsinfo.totalBytes - fsinfo.usedBytes);
|
||||||
}
|
}
|
||||||
#else
|
#endif // ESP8266
|
||||||
|
#ifdef ESP32
|
||||||
if (sel == 0) {
|
if (sel == 0) {
|
||||||
result = LITTLEFS.totalBytes();
|
result = LITTLEFS.totalBytes();
|
||||||
} else {
|
} else {
|
||||||
result = LITTLEFS.totalBytes() - LITTLEFS.usedBytes();
|
result = LITTLEFS.totalBytes() - LITTLEFS.usedBytes();
|
||||||
}
|
}
|
||||||
#endif // ESP8266
|
#endif // ESP32
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UFS_TFAT:
|
case UFS_TFAT:
|
||||||
|
@ -200,21 +202,20 @@ FSInfo64 fsinfo;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t ufs_reject(char *name) {
|
uint8_t ufs_reject(char *name) {
|
||||||
|
|
||||||
char *lcp = strrchr(name,'/');
|
char *lcp = strrchr(name,'/');
|
||||||
if (lcp) {
|
if (lcp) {
|
||||||
name = lcp + 1;
|
name = lcp + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*name=='/') name++;
|
while (*name=='/') { name++; }
|
||||||
if (*name=='_') return 1;
|
if (*name=='_') { return 1; }
|
||||||
if (*name=='.') return 1;
|
if (*name=='.') { return 1; }
|
||||||
|
|
||||||
if (!strncasecmp(name, "SPOTLI~1", REJCMPL)) return 1;
|
if (!strncasecmp(name, "SPOTLI~1", REJCMPL)) { return 1; }
|
||||||
if (!strncasecmp(name, "TRASHE~1", REJCMPL)) return 1;
|
if (!strncasecmp(name, "TRASHE~1", REJCMPL)) { return 1; }
|
||||||
if (!strncasecmp(name, "FSEVEN~1", REJCMPL)) return 1;
|
if (!strncasecmp(name, "FSEVEN~1", REJCMPL)) { return 1; }
|
||||||
if (!strncasecmp(name, "SYSTEM~1", REJCMPL)) return 1;
|
if (!strncasecmp(name, "SYSTEM~1", REJCMPL)) { return 1; }
|
||||||
if (!strncasecmp(name, "System Volume", 13)) return 1;
|
if (!strncasecmp(name, "System Volume", 13)) { return 1; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,35 +226,35 @@ void UFS_form1000(uint32_t number, char *dp, char sc) {
|
||||||
char *sp = str;
|
char *sp = str;
|
||||||
uint32_t inum = strlen(sp)/3;
|
uint32_t inum = strlen(sp)/3;
|
||||||
uint32_t fnum = strlen(sp)%3;
|
uint32_t fnum = strlen(sp)%3;
|
||||||
if (!fnum) inum--;
|
if (!fnum) { inum--; }
|
||||||
for (uint32_t count=0; count<=inum; count++) {
|
for (uint32_t count = 0; count <= inum; count++) {
|
||||||
if (fnum){
|
if (fnum) {
|
||||||
memcpy(dp,sp,fnum);
|
memcpy(dp, sp, fnum);
|
||||||
dp+=fnum;
|
dp += fnum;
|
||||||
sp+=fnum;
|
sp += fnum;
|
||||||
fnum=0;
|
fnum = 0;
|
||||||
} else {
|
} else {
|
||||||
memcpy(dp,sp,3);
|
memcpy(dp, sp, 3);
|
||||||
dp+=3;
|
dp += 3;
|
||||||
sp+=3;
|
sp += 3;
|
||||||
}
|
}
|
||||||
if (count!=inum) {
|
if (count != inum) {
|
||||||
*dp++=sc;
|
*dp++ = sc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*dp=0;
|
*dp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char kUFSCommands[] PROGMEM = "Ufs" "|" // Prefix
|
||||||
const char kUFSCommands[] PROGMEM = "UFS" "|" // Prefix
|
"|" "Type" "|" "Size" "|" "Free";
|
||||||
"|" "TYPE" "|" "SIZE" "|" "FREE";
|
|
||||||
|
|
||||||
void (* const kUFSCommand[])(void) PROGMEM = {
|
void (* const kUFSCommand[])(void) PROGMEM = {
|
||||||
&UFS_info, &UFS_type, &UFS_size, &UFS_free};
|
&UFS_info, &UFS_type, &UFS_size, &UFS_free};
|
||||||
|
|
||||||
void UFS_info(void) {
|
void UFS_info(void) {
|
||||||
Response_P(PSTR("{\"UFS\":{\"TYPE\":%d,\"SIZE\":%d,\"FREE\":%d}}"),ufs_type,ufs_fsinfo(0),ufs_fsinfo(1));
|
Response_P(PSTR("{\"Ufs\":{\"Type\":%d,\"Size\":%d,\"Free\":%d}}"), ufs_type, ufs_fsinfo(0), ufs_fsinfo(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UFS_type(void) {
|
void UFS_type(void) {
|
||||||
ResponseCmndNumber(ufs_type);
|
ResponseCmndNumber(ufs_type);
|
||||||
}
|
}
|
||||||
|
@ -268,24 +269,24 @@ const char UFS_WEB_DIR[] PROGMEM =
|
||||||
"<p><form action='" "ufsd" "' method='get'><button>" "%s" "</button></form></p>";
|
"<p><form action='" "ufsd" "' method='get'><button>" "%s" "</button></form></p>";
|
||||||
const char UFS_FILE_UPLOAD[] PROGMEM = D_SDCARD_DIR;
|
const char UFS_FILE_UPLOAD[] PROGMEM = D_SDCARD_DIR;
|
||||||
const char UFS_FORM_FILE_UPLOAD[] PROGMEM =
|
const char UFS_FORM_FILE_UPLOAD[] PROGMEM =
|
||||||
"<div id='f1' name='f1' style='display:block;'>"
|
"<div id='f1' name='f1' style='display:block;'>"
|
||||||
"<fieldset><legend><b> %s" " </b></legend>";
|
"<fieldset><legend><b> %s" " </b></legend>";
|
||||||
const char UFS_FORM_FILE_UPG[] PROGMEM =
|
const char UFS_FORM_FILE_UPG[] PROGMEM =
|
||||||
"<form method='post' action='ufsu' enctype='multipart/form-data'>"
|
"<form method='post' action='ufsu' enctype='multipart/form-data'>"
|
||||||
"<br/><input type='file' name='ufsu'><br/>"
|
"<br/><input type='file' name='ufsu'><br/>"
|
||||||
"<br/><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>" D_START " %s</button></form>";
|
"<br/><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>" D_START " %s</button></form>";
|
||||||
const char UFS_FORM_FILE_UPGc[] PROGMEM =
|
const char UFS_FORM_FILE_UPGc[] PROGMEM =
|
||||||
"<div style='text-align:left;color:green;'>total size: %s kB - free: %s kB</div>";
|
"<div style='text-align:left;color:green;'>total size: %s kB - free: %s kB</div>";
|
||||||
const char UFS_FORM_SDC_DIRa[] PROGMEM =
|
const char UFS_FORM_SDC_DIRa[] PROGMEM =
|
||||||
"<div style='text-align:left'>";
|
"<div style='text-align:left'>";
|
||||||
const char UFS_FORM_SDC_DIRc[] PROGMEM =
|
const char UFS_FORM_SDC_DIRc[] PROGMEM =
|
||||||
"</div>";
|
"</div>";
|
||||||
const char UFS_FORM_FILE_UPGb[] PROGMEM =
|
const char UFS_FORM_FILE_UPGb[] PROGMEM =
|
||||||
"</fieldset>"
|
"</fieldset>"
|
||||||
"</div>"
|
"</div>"
|
||||||
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>" D_UPLOAD_STARTED " ...</b></div>";
|
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>" D_UPLOAD_STARTED " ...</b></div>";
|
||||||
const char UFS_FORM_SDC_DIRd[] PROGMEM =
|
const char UFS_FORM_SDC_DIRd[] PROGMEM =
|
||||||
"<pre><a href='%s' file='%s'>%s</a></pre>";
|
"<pre><a href='%s' file='%s'>%s</a></pre>";
|
||||||
const char UFS_FORM_SDC_DIRb[] PROGMEM =
|
const char UFS_FORM_SDC_DIRb[] PROGMEM =
|
||||||
"<pre><a href='%s' file='%s'>%s</a> %s : %8d</pre>";
|
"<pre><a href='%s' file='%s'>%s</a> %s : %8d</pre>";
|
||||||
const char UFS_FORM_SDC_HREF[] PROGMEM =
|
const char UFS_FORM_SDC_HREF[] PROGMEM =
|
||||||
|
@ -324,7 +325,6 @@ void UFSdirectory(void) {
|
||||||
WSContentSpaceButton(BUTTON_CONFIGURATION);
|
WSContentSpaceButton(BUTTON_CONFIGURATION);
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
Web.upload_error = 0;
|
Web.upload_error = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UFS_ListDir(char *path, uint8_t depth) {
|
void UFS_ListDir(char *path, uint8_t depth) {
|
||||||
|
@ -337,15 +337,18 @@ void UFS_ListDir(char *path, uint8_t depth) {
|
||||||
if (dir) {
|
if (dir) {
|
||||||
dir.rewindDirectory();
|
dir.rewindDirectory();
|
||||||
if (strlen(path)>1) {
|
if (strlen(path)>1) {
|
||||||
snprintf_P(npath, sizeof(npath), PSTR("http://%s/ufsd?download=%s"), WiFi.localIP().toString().c_str(),path);
|
snprintf_P(npath, sizeof(npath), PSTR("http://%s/ufsd?download=%s"), WiFi.localIP().toString().c_str(), path);
|
||||||
for (uint8_t cnt = strlen(npath) - 1; cnt>0; cnt--) {
|
for (uint32_t cnt = strlen(npath) - 1; cnt > 0; cnt--) {
|
||||||
if (npath[cnt]=='/') {
|
if (npath[cnt] == '/') {
|
||||||
if (npath[cnt - 1]=='=') npath[cnt + 1] = 0;
|
if (npath[cnt - 1] == '=') {
|
||||||
else npath[cnt] = 0;
|
npath[cnt + 1] = 0;
|
||||||
|
} else {
|
||||||
|
npath[cnt] = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WSContentSend_P(UFS_FORM_SDC_DIRd, npath,path, "..");
|
WSContentSend_P(UFS_FORM_SDC_DIRd, npath, path, "..");
|
||||||
}
|
}
|
||||||
char *ep;
|
char *ep;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -355,17 +358,17 @@ void UFS_ListDir(char *path, uint8_t depth) {
|
||||||
}
|
}
|
||||||
// esp32 returns path here, shorten to filename
|
// esp32 returns path here, shorten to filename
|
||||||
ep = (char*)entry.name();
|
ep = (char*)entry.name();
|
||||||
if (*ep=='/') ep++;
|
if (*ep == '/') { ep++; }
|
||||||
char *lcp = strrchr(ep,'/');
|
char *lcp = strrchr(ep,'/');
|
||||||
if (lcp) {
|
if (lcp) {
|
||||||
ep = lcp + 1;
|
ep = lcp + 1;
|
||||||
}
|
}
|
||||||
time_t tm = entry.getLastWrite();
|
time_t tm = entry.getLastWrite();
|
||||||
char tstr[24];
|
char tstr[24];
|
||||||
strftime(tstr, 22, "%d-%m-%Y - %H:%M:%S ", localtime(&tm));
|
strftime(tstr, 22, "%d-%m-%Y - %H:%M:%S ", localtime(&tm)); // Theo note to me. Isn't strftime expensive? SHould use ISO Date/Time
|
||||||
|
|
||||||
char *pp = path;
|
char *pp = path;
|
||||||
if (!*(pp + 1)) pp++;
|
if (!*(pp + 1)) { pp++; }
|
||||||
char *cp = name;
|
char *cp = name;
|
||||||
// osx formatted disks contain a lot of stuff we dont want
|
// osx formatted disks contain a lot of stuff we dont want
|
||||||
if (!ufs_reject((char*)ep)) {
|
if (!ufs_reject((char*)ep)) {
|
||||||
|
@ -376,17 +379,17 @@ void UFS_ListDir(char *path, uint8_t depth) {
|
||||||
|
|
||||||
sprintf(cp, format, ep);
|
sprintf(cp, format, ep);
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, WiFi.localIP().toString().c_str(), pp,ep);
|
snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, WiFi.localIP().toString().c_str(), pp, ep);
|
||||||
WSContentSend_P(UFS_FORM_SDC_DIRd, npath,ep,name);
|
WSContentSend_P(UFS_FORM_SDC_DIRd, npath, ep, name);
|
||||||
uint8_t plen = strlen(path);
|
uint8_t plen = strlen(path);
|
||||||
if (plen>1) {
|
if (plen > 1) {
|
||||||
strcat(path, "/");
|
strcat(path, "/");
|
||||||
}
|
}
|
||||||
strcat(path, ep);
|
strcat(path, ep);
|
||||||
UFS_ListDir(path, depth + 4);
|
UFS_ListDir(path, depth + 4);
|
||||||
path[plen] = 0;
|
path[plen] = 0;
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, WiFi.localIP().toString().c_str(), pp,ep);
|
snprintf_P(npath, sizeof(npath), UFS_FORM_SDC_HREF, WiFi.localIP().toString().c_str(), pp, ep);
|
||||||
WSContentSend_P(UFS_FORM_SDC_DIRb, npath, ep, name, tstr, entry.size());
|
WSContentSend_P(UFS_FORM_SDC_DIRb, npath, ep, name, tstr, entry.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,13 +404,13 @@ uint8_t UFS_DownloadFile(char *file) {
|
||||||
WiFiClient download_Client;
|
WiFiClient download_Client;
|
||||||
|
|
||||||
if (!ufsp->exists(file)) {
|
if (!ufsp->exists(file)) {
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("file not found"));
|
AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: File not found"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
download_file = ufsp->open(file, UFS_FILE_READ);
|
download_file = ufsp->open(file, UFS_FILE_READ);
|
||||||
if (!download_file) {
|
if (!download_file) {
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("could not open file"));
|
AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: Could not open file"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,8 +426,8 @@ uint8_t UFS_DownloadFile(char *file) {
|
||||||
|
|
||||||
char attachment[100];
|
char attachment[100];
|
||||||
char *cp;
|
char *cp;
|
||||||
for (uint8_t cnt = strlen(file); cnt>=0; cnt--) {
|
for (uint32_t cnt = strlen(file); cnt >= 0; cnt--) {
|
||||||
if (file[cnt]=='/') {
|
if (file[cnt] == '/') {
|
||||||
cp = &file[cnt + 1];
|
cp = &file[cnt + 1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -434,16 +437,16 @@ uint8_t UFS_DownloadFile(char *file) {
|
||||||
WSSend(200, CT_STREAM, "");
|
WSSend(200, CT_STREAM, "");
|
||||||
|
|
||||||
uint8_t buff[512];
|
uint8_t buff[512];
|
||||||
uint16_t bread;
|
uint32_t bread;
|
||||||
|
|
||||||
// transfer is about 150kb/s
|
// transfer is about 150kb/s
|
||||||
uint8_t cnt = 0;
|
uint32_t cnt = 0;
|
||||||
while (download_file.available()) {
|
while (download_file.available()) {
|
||||||
bread = download_file.read(buff, sizeof(buff));
|
bread = download_file.read(buff, sizeof(buff));
|
||||||
uint16_t bw = download_Client.write((const char*)buff, bread);
|
uint32_t bw = download_Client.write((const char*)buff, bread);
|
||||||
if (!bw) break;
|
if (!bw) { break; }
|
||||||
cnt++;
|
cnt++;
|
||||||
if (cnt>7) {
|
if (cnt > 7) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
//if (glob_script_mem.script_loglevel & 0x80) {
|
//if (glob_script_mem.script_loglevel & 0x80) {
|
||||||
// this indeed multitasks, but is slower 50 kB/s
|
// this indeed multitasks, but is slower 50 kB/s
|
||||||
|
@ -464,16 +467,20 @@ void UFS_Upload(void) {
|
||||||
sprintf(npath, "%s/%s", ufs_path, upload.filename.c_str());
|
sprintf(npath, "%s/%s", ufs_path, upload.filename.c_str());
|
||||||
ufsp->remove(npath);
|
ufsp->remove(npath);
|
||||||
ufs_upload_file = ufsp->open(npath, UFS_FILE_WRITE);
|
ufs_upload_file = ufsp->open(npath, UFS_FILE_WRITE);
|
||||||
if (!ufs_upload_file) Web.upload_error = 1;
|
if (!ufs_upload_file) { Web.upload_error = 1; }
|
||||||
} else if(upload.status == UPLOAD_FILE_WRITE) {
|
}
|
||||||
if (ufs_upload_file) ufs_upload_file.write(upload.buf, upload.currentSize);
|
else if (upload.status == UPLOAD_FILE_WRITE) {
|
||||||
} else if(upload.status == UPLOAD_FILE_END) {
|
if (ufs_upload_file) {
|
||||||
if (ufs_upload_file) ufs_upload_file.close();
|
ufs_upload_file.write(upload.buf, upload.currentSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (upload.status == UPLOAD_FILE_END) {
|
||||||
|
if (ufs_upload_file) { ufs_upload_file.close(); }
|
||||||
if (Web.upload_error) {
|
if (Web.upload_error) {
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("HTP: upload error"));
|
AddLog_P(LOG_LEVEL_INFO, PSTR("HTP: upload error"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Web.upload_error=1;
|
Web.upload_error = 1;
|
||||||
WSSend(500, CT_PLAIN, F("500: couldn't create file"));
|
WSSend(500, CT_PLAIN, F("500: couldn't create file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -484,7 +491,7 @@ void UFSFileUploadSuccess(void) {
|
||||||
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPLOAD " <font color='#"));
|
WSContentSend_P(PSTR("<div style='text-align:center;'><b>" D_UPLOAD " <font color='#"));
|
||||||
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br/>"), WebColor(COL_TEXT_SUCCESS));
|
WSContentSend_P(PSTR("%06x'>" D_SUCCESSFUL "</font></b><br/>"), WebColor(COL_TEXT_SUCCESS));
|
||||||
WSContentSend_P(PSTR("</div><br/>"));
|
WSContentSend_P(PSTR("</div><br/>"));
|
||||||
WSContentSend_P(PSTR("<p><form action='%s' method='get'><button>%s</button></form></p>"),"/ufsd",D_UPL_DONE);
|
WSContentSend_P(PSTR("<p><form action='%s' method='get'><button>%s</button></form></p>"), "/ufsd", D_UPL_DONE);
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +520,10 @@ bool Xdrv98(uint8_t function) {
|
||||||
case FUNC_WEB_ADD_HANDLER:
|
case FUNC_WEB_ADD_HANDLER:
|
||||||
Webserver->on("/ufsd", UFSdirectory);
|
Webserver->on("/ufsd", UFSdirectory);
|
||||||
Webserver->on("/ufsu", HTTP_GET, UFSFileUploadSuccess);
|
Webserver->on("/ufsu", HTTP_GET, UFSFileUploadSuccess);
|
||||||
Webserver->on("/ufsu", HTTP_POST,[]() { Webserver->sendHeader("Location","/ufsu");Webserver->send(303);}, UFS_Upload);
|
Webserver->on("/ufsu", HTTP_POST,[]() {
|
||||||
|
Webserver->sendHeader("Location","/ufsu");
|
||||||
|
Webserver->send(303);
|
||||||
|
}, UFS_Upload);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue