Skip to content

Commit 531974a

Browse files
committed
add how to run example description, fix upload/edit mode
rename resource to data folder to match original example
1 parent ede0eff commit 531974a

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

examples/MassStorage/msc_esp32_file_browser/msc_esp32_file_browser.ino

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@
99
any redistribution
1010
*********************************************************************/
1111

12-
/* This example demo how to expose on-board external Flash as USB Mass Storage.
13-
* Following library is required
12+
/* This example is based on "arduino-esp32/libraries/WebServer/examples/FSBrowser"
13+
* to expose on-board external Flash as USB Mass Storage and webserver. Both interfaces
14+
* can make changes to file system
15+
*
16+
* How to run this example
17+
* 1. Create secrets.h and define your "SECRET_SSID" and "SECRET_PASSWORD"
18+
* 2. Compile and upload this sketch
19+
* 3. Your ESP will be expose as MassStorage device.
20+
* 4. If it is your first run (otherwise skip this step):
21+
* - you may need to format the drive as FAT. Note: If your PC failed to format, you could format
22+
* it using follow sketch "https://github.com/adafruit/Adafruit_SPIFlash/tree/master/examples/SdFat_format"
23+
* - Copy all files in 'data/' folder of this example to the root directory of the MassStorage disk drive
24+
* 5. When prompted, open http://esp32fs.local/edit to access the file browser
25+
* 6. Try to modify USB drive then refresh your browser to see if the change is updated
26+
* 7.
27+
*
28+
* NOTE: Following library is required
1429
* - Adafruit_SPIFlash https://github.com/adafruit/Adafruit_SPIFlash
1530
* - SdFat https://github.com/adafruit/SdFat
16-
*
17-
* Note: Adafruit fork of SdFat enabled ENABLE_EXTENDED_TRANSFER_CLASS and FAT12_SUPPORT
18-
* in SdFatConfig.h, which is needed to run SdFat on external flash. You can use original
19-
* SdFat library and manually change those macros
2031
*/
2132

2233
#include "SPI.h"
@@ -118,7 +129,7 @@ void setupServer(void)
118129
MDNS.begin(host);
119130
DBG_SERIAL.print("Open http://");
120131
DBG_SERIAL.print(host);
121-
DBG_SERIAL.println(".local/edit to see the file browser");
132+
DBG_SERIAL.println(".local/edit to access the file browser");
122133

123134
//SERVER INIT
124135

@@ -272,12 +283,15 @@ void handleFileUpload() {
272283
filename = "/" + filename;
273284
}
274285
DBG_SERIAL.print("handleFileUpload Name: "); DBG_SERIAL.println(filename);
275-
fsUploadFile = fatfs.open(filename, O_WRITE);
286+
fsUploadFile = fatfs.open(filename, O_WRITE | O_CREAT | O_TRUNC);
276287
filename = String();
277288
} else if (upload.status == UPLOAD_FILE_WRITE) {
278-
//DBG_SERIAL.print("handleFileUpload Data: "); DBG_SERIAL.println(upload.currentSize);
289+
DBG_SERIAL.print("handleFileUpload Data: "); DBG_SERIAL.println(upload.currentSize);
279290
if (fsUploadFile) {
280291
fsUploadFile.write(upload.buf, upload.currentSize);
292+
}else
293+
{
294+
DBG_SERIAL.print("handleFileUpload file is not opened !!!");
281295
}
282296
} else if (upload.status == UPLOAD_FILE_END) {
283297
if (fsUploadFile) {

0 commit comments

Comments
 (0)