EasyManua.ls Logo

Espressif Systems ESP8266EX - How to Use the SPIFFS File System

Espressif Systems ESP8266EX
41 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
!
3. Sample Codes
#endif
3.4.3. How to Use the SPIFFS File System
1. Initialize the SPIFFS file system by calling esp_spiffs_init.
void󰲧spiffs_fs1_init(void)
{
󰲧󰲧󰲧󰲧struct󰲧esp_spiffs_config󰲧config;
󰲧󰲧󰲧󰲧config.phys_size󰲧=󰲧FS1_FLASH_SIZE;
󰲧󰲧󰲧󰲧config.phys_addr󰲧=󰲧FS1_FLASH_ADDR;
󰲧󰲧󰲧󰲧config.phys_erase_block󰲧=󰲧SECTOR_SIZE;
󰲧󰲧󰲧󰲧config.log_block_size󰲧=󰲧LOG_BLOCK;
󰲧󰲧󰲧󰲧config.log_page_size󰲧=󰲧LOG_PAGE;
󰲧󰲧󰲧󰲧config.fd_buf_size󰲧=󰲧FD_BUF_SIZE󰲧*󰲧2;
󰲧󰲧󰲧󰲧config.cache_buf_size󰲧=󰲧CACHE_BUF_SIZE;
󰲧󰲧󰲧󰲧esp_spiffs_init(&config);
}
2. Open and create a new file, and write the data in it.
char󰲧*buf="hello󰲧world";
char󰲧out[20]󰲧=󰲧{0};
int󰲧pfd󰲧=󰲧open("myfile",󰲧O_TRUNC󰲧|󰲧O_CREAT󰲧|󰲧O_RDWR,󰲧S_IRUSR󰲧|󰲧S_IWUSR);
if(pfd󰲧<=󰲧3)󰲧{
󰲧󰲧󰲧󰲧printf("open󰲧file󰲧error󰲧\n");
}
int󰲧write_byte󰲧=󰲧write(pfd,󰲧buf,󰲧strlen(buf));
if󰲧(write_byte󰲧<=󰲧0)
{
󰲧󰲧󰲧󰲧printf("write󰲧file󰲧error󰲧\n");
}
close(pfd);
3. Read date via the file system.
open("myfile",O_RDWR);
if󰲧(read(pfd,󰲧out,󰲧20)󰲧<󰲧0)
󰲧󰲧󰲧󰲧printf("read󰲧errno󰲧\n");
close(pfd);
printf("-->󰲧%s󰲧<--\n",󰲧out);
Espressif
! /!30 37
2017.05

Other manuals for Espressif Systems ESP8266EX

Related product manuals