SPIFFS is working, as best I can tell - I've used the example SPIFFS code to add the functionality to my project and it has formatted the file system on the ESP32 and initialises just fine, according to the serial console.
I've now tried to upload some files (just .htm, .css and .js files) which I've done as follows:
- Relevant files were placed in a folder (.data)
I've used mkspiffs to build an image of the file folder:Code: Select all
mkspiffs -c data -b 4096 -p 256 -s 0x100000 spiffs.bin
Code: Select all
python esptool.py --chip esp32 --port COM14 --baud 115200 write_flash -z 0xF0000 spiffs.bin
The ESP32 is reset and the following code executes - it should say that the files exist, but it says it can't find them!
Code: Select all
void initialise_SPIFFS()
{
ESP_LOGI(TAG, "Initializing SPIFFS");
esp_vfs_spiffs_conf_t conf = {
.base_path = "/spiffs",
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = true
};
// Use settings defined above to initialize and mount SPIFFS filesystem.
// Note: esp_vfs_spiffs_register is an all-in-one convenience function.
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return;
}
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
} else {
// SPIFFS set up a-ok
SPIFFS_OK = true;
// Check if files exist
struct stat st;
if (stat("/spiffs/dashboard.css", &st) == 0) {
ESP_LOGI(TAG, "Found dashboard.css!");
} else {
ESP_LOGI(TAG, "Can't find dashboard.css!");
}
if (stat("/spiffs/index.htm", &st) == 0) {
ESP_LOGI(TAG, "Found index.htm!");
} else {
ESP_LOGI(TAG, "Can't find index.htm!");
}
if (stat("/spiffs/scripts.js", &st) == 0) {
ESP_LOGI(TAG, "Found scripts.js!");
} else {
ESP_LOGI(TAG, "Can't find scripts.js!");
}
}
}