This feature allows you to browse and download log files from the ESP32 SD card via serial connection using an interactive TUI (Text User Interface).
python download_log.pyThe script will launch an interactive file browser where you can:
- Navigate with arrow keys (↑/↓)
- Press ENTER to download a file
- Press 'r' to refresh the file list
- Press 'q' to quit
Edit the following variables at the top of download_log.py:
PORT: Serial port (default:/dev/ttyACM0)BAUD: Baud rate (default:115200)DOWNLOAD_DIR: Where to save downloaded logs (default:./logs)
- Interactive TUI: Browse files with arrow keys
- File information: Shows file sizes in human-readable format
- Live progress: Real-time download progress indicator
- Auto-timestamping: Downloaded files include timestamp to prevent overwrites
- Error handling: Clear error messages for troubleshooting
- Connects to ESP32 via serial
- Sends
LIST_FILEScommand to get all files on SD card - Displays an interactive menu with file names and sizes
- On selection, sends
DOWNLOAD_FILE:<filename>to download - Saves file locally with timestamp:
logs/<filename>_YYYYMMDD_HHMMSS.csv
main/serial_commands.h- Command handler headermain/serial_commands.cc- Command handler implementation
main/main_functions.cc- Added serial command processing to main loopmain/CMakeLists.txt- Added serial_commands.cc to buildmain/drive_system/depth_sensor.h- Exposed g_depth_log_filenamemain/drive_system/depth_sensor.cc- Made g_depth_log_filename non-static
Commands are sent as ASCII text over serial (newline-terminated):
-
GET_LOG_FILENAME
- Response:
LOG_FILENAME:<filename> - Example:
LOG_FILENAME:/revised_log_0024.csv - Gets the current active log file
- Response:
-
LIST_FILES
- Responses:
FILE_LIST_START- Beginning of file listFILE:<name>:<size>- Regular file with size in bytesDIR:<name>- Directory entryFILE_LIST_END- End of file listFILE_LIST_ERROR:<message>- Error message
- Lists all files and directories in /sdcard
- Responses:
-
DOWNLOAD_FILE:
- Responses:
FILE_SIZE:<bytes>- File size in bytesFILE_START- Beginning of file data<file contents>- Raw file dataFILE_END- End of file dataFILE_ERROR:<message>- Error message
- Downloads a specific file from SD card
- Responses:
-
Build and flash the firmware:
idf.py build flash
-
Run the download script:
python download_log.py
-
Navigate the file browser with arrow keys
-
Press ENTER on a file to download it
-
Check the
logs/directory for downloaded files
- No response: Check that the serial port is correct and ESP32 is powered
- Empty file list: Verify SD card is inserted and has files
- Timeout: Increase
TIMEOUTvalue indownload_log.py - Baud rate mismatch: Ensure Python script and ESP32 both use 115200
- TUI display issues: Make sure your terminal supports curses (most Linux/Mac terminals do)
pip install pyserialNo additional libraries needed - uses Python's built-in curses module for the TUI.
================================================================================
ESP32 SD Card File Browser
================================================================================
↑/↓: Navigate | ENTER: Download | q: Quit | r: Refresh
--------------------------------------------------------------------------------
[FILE] counter.txt 4 B
> [FILE] revised_log_0023.csv 45.2 KB
[FILE] revised_log_0024.csv 67.8 KB
[DIR] logs
--------------------------------------------------------------------------------
Found 4 items