mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-04 03:50:36 +08:00
Fix SD occupation show 0.00% is 0 or less than 1%
Add missing SD file stream and download Stop streaming if no more connection for SD and FS Clean some debug
This commit is contained in:
parent
aadb8b01f4
commit
869a36e187
@ -1232,11 +1232,13 @@ bool Commands::ESP420(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printLN("");
|
||||
}
|
||||
#endif //ESP_DEBUG_FEATURE
|
||||
|
||||
|
||||
//Target Firmware
|
||||
if (!plain) {
|
||||
output->print (",{\"id\":\"targetfw");
|
||||
} else output->print ("Target Fw");
|
||||
} else {
|
||||
output->print ("Target Fw");
|
||||
}
|
||||
if (!plain) {
|
||||
output->print ("\",\"value\":\"");
|
||||
} else {
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define _VERSION_ESP3D_H
|
||||
|
||||
//version and sources location
|
||||
#define FW_VERSION "3.0.0.a48"
|
||||
#define FW_VERSION "3.0.0.a49"
|
||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||
|
||||
#endif //_VERSION_ESP3D_H
|
||||
|
@ -198,7 +198,11 @@ void HTTP_Server::handleSDFileList ()
|
||||
buffer2send += "],\"path\":\"" + path + "\",";
|
||||
|
||||
if (ESP_SD::totalBytes()>0) {
|
||||
buffer2send += "\"occupation\":\"" + String(100.0*ESP_SD::usedBytes()/ESP_SD::totalBytes()) + "\",";
|
||||
float occupation = 100.0*ESP_SD::usedBytes()/ESP_SD::totalBytes();
|
||||
if ((occupation < 1) && (ESP_SD::usedBytes()>0)) {
|
||||
occupation=1;
|
||||
}
|
||||
buffer2send += "\"occupation\":\"" + String((int)round(occupation)) + "\",";
|
||||
} else {
|
||||
status = "SD Error";
|
||||
buffer2send += "\"occupation\":\"0\",";
|
||||
|
@ -28,6 +28,9 @@
|
||||
#endif //ARDUINO_ARCH_ESP8266
|
||||
#include "../../filesystem/esp_filesystem.h"
|
||||
#include "../../authentication/authentication_service.h"
|
||||
#if defined(SD_DEVICE)
|
||||
#include "../../filesystem/esp_sd.h"
|
||||
#endif //SD_DEVICE
|
||||
|
||||
//Handle not registred path on FS neither SD ///////////////////////
|
||||
void HTTP_Server:: handle_not_found()
|
||||
@ -52,6 +55,23 @@ void HTTP_Server:: handle_not_found()
|
||||
}
|
||||
#endif //#if defined (FILESYSTEM_FEATURE)
|
||||
|
||||
#if defined (SD_DEVICE)
|
||||
if (path.startsWith("/sd/")) {
|
||||
path = path.substring(3);
|
||||
pathWithGz = path + ".gz";
|
||||
if(ESP_SD::exists(pathWithGz.c_str()) || ESP_SD::exists(path.c_str())) {
|
||||
if(ESP_SD::exists(pathWithGz.c_str())) {
|
||||
_webserver->sendHeader("Content-Encoding", "gzip");
|
||||
path = pathWithGz;
|
||||
}
|
||||
if(!StreamSDFile(path.c_str(),contentType.c_str())) {
|
||||
log_esp3d("Stream `%s` failed", path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif //#if defined (SD_DEVICE)
|
||||
|
||||
#ifdef FILESYSTEM_FEATURE
|
||||
//check local page
|
||||
path = "/404.htm";
|
||||
@ -71,32 +91,5 @@ void HTTP_Server:: handle_not_found()
|
||||
//let's keep simple just send minimum
|
||||
_webserver->send(404);
|
||||
|
||||
/*
|
||||
|
||||
#ifdef ENABLE_SD_CARD
|
||||
if ((path.substring(0,4) == "/SD/")) {
|
||||
//remove /SD
|
||||
path = path.substring(3);
|
||||
if(SD.exists((char *)pathWithGz.c_str()) || SD.exists((char *)path.c_str())) {
|
||||
if(SD.exists((char *)pathWithGz.c_str())) {
|
||||
path = pathWithGz;
|
||||
}
|
||||
File datafile = SD.open((char *)path.c_str());
|
||||
if (datafile) {
|
||||
if( _webserver->streamFile(datafile, contentType) == datafile.size()) {
|
||||
datafile.close();
|
||||
COMMANDS::wait(0);
|
||||
return;
|
||||
} else{
|
||||
datafile.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
String content = "cannot find ";
|
||||
content+=path;
|
||||
_webserver->send(404,"text/plain",content.c_str());
|
||||
return;
|
||||
} else
|
||||
#endif*/
|
||||
}
|
||||
#endif //HTTP_FEATURE
|
||||
|
@ -131,10 +131,6 @@ void HTTP_Server::SDFileupload ()
|
||||
_upload_status=UPLOAD_STATUS_FAILED;
|
||||
pushError(ESP_ERROR_FILE_CLOSE, "File close failed");
|
||||
}
|
||||
Serial.print(filesize);
|
||||
Serial.print(" B in ");
|
||||
Serial.print((millis()-timecheck) / 1000);
|
||||
Serial.println(" sec");
|
||||
//Upload cancelled
|
||||
} else {
|
||||
if (_upload_status == UPLOAD_STATUS_ONGOING) {
|
||||
|
@ -33,7 +33,10 @@
|
||||
#include "../../core/settings_esp3d.h"
|
||||
#include "../filesystem/esp_filesystem.h"
|
||||
#include "../websocket/websocket_server.h"
|
||||
#if defined(SD_DEVICE)
|
||||
#include "../filesystem/esp_sd.h"
|
||||
|
||||
#endif //SD_DEVICE
|
||||
bool HTTP_Server::_started = false;
|
||||
uint16_t HTTP_Server::_port = 0;
|
||||
WEBSERVER * HTTP_Server::_webserver = nullptr;
|
||||
@ -97,7 +100,7 @@ bool HTTP_Server::StreamFSFile(const char* filename, const char * contentType)
|
||||
_webserver->setContentLength(totalFileSize);
|
||||
_webserver->send(200, contentType, "");
|
||||
uint8_t buf[1024];
|
||||
while (!done) {
|
||||
while (!done && _webserver->client().connected()) {
|
||||
Hal::wait(0);
|
||||
int v = datafile.read(buf,1024);
|
||||
if ((v == -1) || (v == 0)) {
|
||||
@ -117,6 +120,41 @@ bool HTTP_Server::StreamFSFile(const char* filename, const char * contentType)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined (SD_DEVICE)
|
||||
bool HTTP_Server::StreamSDFile(const char* filename, const char * contentType)
|
||||
{
|
||||
ESP_SDFile datafile = ESP_SD::open(filename);
|
||||
if (!datafile) {
|
||||
return false;
|
||||
}
|
||||
size_t totalFileSize = datafile.size();
|
||||
size_t i = 0;
|
||||
bool done = false;
|
||||
_webserver->setContentLength(totalFileSize);
|
||||
_webserver->send(200, contentType, "");
|
||||
uint8_t buf[1024];
|
||||
while (!done && _webserver->client().connected()) {
|
||||
Hal::wait(0);
|
||||
int v = datafile.read(buf,1024);
|
||||
if ((v == -1) || (v == 0)) {
|
||||
done = true;
|
||||
} else {
|
||||
_webserver->client().write(buf,v);
|
||||
Serial.print(".");
|
||||
i+=v;
|
||||
}
|
||||
if (i >= totalFileSize) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
datafile.close();
|
||||
if ( i != totalFileSize) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif //SD_DEVICE
|
||||
|
||||
void HTTP_Server::pushError(int code, const char * st, bool web_error, uint16_t timeout)
|
||||
{
|
||||
if (websocket_terminal_server.started() && st) {
|
||||
|
@ -90,6 +90,7 @@ private:
|
||||
#ifdef SD_DEVICE
|
||||
static void SDFileupload ();
|
||||
static void handleSDFileList ();
|
||||
static bool StreamSDFile(const char* filename, const char * contentType);
|
||||
#endif //SD_DEVICE
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user