# Wi-Fi Files VFS
This is a small host-backed file system for ESP32 targets that cannot use SDIO yet or no hardware sdcard slot exists on board.
The ESP side registers an ESP-IDF VFS, so normal calls such as `fopen`, `fread`,
`fwrite`, `fseek`, `fclose`, `opendir`, and `readdir` work on the configured
mount point.
## Host Server
Edit `server/wifi_files.json` to map ESP-visible paths to host directories:
```json
{
"bind": "0.0.0.0",
"port": 3333,
"read_only": false,
"roots": {
"/": "./shared",
"/media": "/home/user/test_media"
}
}
```
Run the server:
```bash
cd components/wifi_fs/server
python3 wifi_file_server.py -c wifi_files.json
```
Add `-v` to log open/close events and throughput. The report prints every 5s
while a file is active and once more when it closes:
```bash
python3 wifi_file_server.py -c wifi_files.json -v
```
If the ESP opens `/sdcard/a.mp3`, the server maps it to `./shared/a.mp3`.
If the ESP opens `/sdcard/media/a.mp3`, the server maps it to
`/home/user/test_media/a.mp3`.
## ESP-IDF Use
Add this directory as an extra component, or copy `wifi_files` into your project's
`components` directory. Then mount it before using file APIs:
```c
#include "wifi_fs.h"
ESP_ERROR_CHECK(wifi_fs_connect_wifi(&(wifi_fs_wifi_config_t) {
.ssid = "my_ap",
.password = "my_password",
}));
ESP_ERROR_CHECK(wifi_fs_mount(&(wifi_fs_mount_config_t) {
.mount_point = "/sdcard",
.server_ip = "192.168.1.10",
.server_port = 3333,
.max_files = 8,
}));
FILE *fp = fopen("/sdcard/test.bin", "rb");
fseek(fp, 1024, SEEK_SET);
uint8_t buf[256];
fread(buf, 1, sizeof(buf), fp);
fclose(fp);
DIR *dir = opendir("/sdcard");
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
```
idf.py add-dependency "tempotian/wifi_fs^0.6.0"