ESP32 支持 SPIFF 了,但是用 ESP8266 的代码测试确无法使用。
查了下资料,需要给 begin 添加一个参数。之后工作正常。
```
if(!SPIFFS.begin(true)){
Serial.println("SPIFFS Mount Failed");
return;
}
```
比较完整的示例:
```
#include "SPIFFS.h"
void setup() {
Serial.begin(115200);
if (!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
File file = SPIFFS.open("/test.txt", FILE_WRITE);
if (!file) {
Serial.println("There was an error opening the file for writing");
return;
}
if (file.print("TEST")) {
Serial.println("File was written");
} else {
Serial.println("File write failed");
}
file.close();
}
void loop() {}
```
https://github.com/espressif/arduino-esp32/blob/master/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino
https://www.tutorialspoint.com/esp32_for_iot/esp32_for_iot_spiffs_storage.htm