Skip to content

Commit 30a534a

Browse files
author
laelhalawani
committed
docs: enhance README with detailed download command descriptions and usage examples
1 parent e60d451 commit 30a534a

1 file changed

Lines changed: 65 additions & 33 deletions

File tree

README.md

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It leverages `esptool` for flashing firmware and `mpremote` for file system oper
99
* Flash MicroPython firmware (downloads official ESP32-C3 USB-enabled firmware by default).
1010
* List available serial ports and set a default device.
1111
* Upload individual files, directory contents, or entire directories to the device.
12-
* Download files or entire directories from the device.
12+
* Download files, directory contents, or entire directories from the device using a unified command.
1313
* List files, display directory trees, and delete files/directories on the device.
1414
* Run MicroPython scripts remotely.
1515
* Simplified commands for common operations.
@@ -85,7 +85,7 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
8585
**Shorthand Usage:**
8686
```bash
8787
# Ensure device port is set first (e.g., esp32 device COM5)
88-
esp32 flash
88+
esp32 flash
8989
```
9090
This will use the default firmware URL.
9191
@@ -115,12 +115,12 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
115115
**Scenarios & Examples:**
116116
1. **Upload a single file to root:**
117117
```bash
118-
esp32 upload main.py
118+
esp32 upload main.py
119119
# Result on ESP32: /main.py
120120
```
121121
2. **Upload a single file to a specific remote directory:**
122122
```bash
123-
esp32 upload utils.py lib
123+
esp32 upload utils.py lib
124124
# Result on ESP32: /lib/utils.py (lib/ will be created if needed)
125125
```
126126
3. **Upload contents of a local directory to root:**
@@ -155,39 +155,70 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
155155
156156
### 4.4 Downloading Files and Directories
157157
158-
* **`esp32 download <remote_file_path> [local_target_path]`**
159-
Downloads a single file from the ESP32 to your computer.
160-
* `remote_file_path`: The full path to the file on the ESP32 (e.g., `main.py`, `lib/utils.py`).
161-
* `local_target_path` (optional): The name/path to save the file as locally. Defaults to the remote file's basename in the current directory.
158+
* **`esp32 download <remote_source_path> [local_target_path]`**
159+
Downloads files or directories from the ESP32 to your computer. This command behaves similarly to `upload` but in reverse.
162160
163-
**Scenarios & Examples:**
164-
```bash
165-
esp32 download main.py
166-
# Saves /main.py from device to ./main.py locally
167-
168-
esp32 download lib/config.json backup_config.json
169-
# Saves /lib/config.json from device to ./backup_config.json locally
170-
```
161+
**Understanding `remote_source_path` and trailing slashes for directories:**
162+
* If `remote_source_path` points to a **file** on the ESP32 (e.g., `/data/log.txt`): The file is downloaded.
163+
* If `remote_source_path` points to a **directory** on the ESP32 and *ends with a `/`* (e.g., `/logs/`): The *contents* of that remote directory are downloaded into the specified `local_target_path`.
164+
* To download the contents of the root directory, use `//` (e.g., `esp32 download // local_root_backup`).
165+
* If `remote_source_path` points to a **directory** on the ESP32 and *does not end with a `/`* (e.g., `/config`): The directory `config` *itself* (including its contents) is downloaded and created within the `local_target_path`.
171166
172-
* **`esp32 download_all <remote_source_dir> [local_target_dir]`**
173-
Recursively downloads the contents of a directory from the ESP32 to your computer.
174-
* `remote_source_dir`: The directory on the ESP32 to download (e.g., `lib`, `data`).
175-
* `local_target_dir` (optional): The local directory to save into. Defaults to a new directory with the same name as `remote_source_dir` in the CWD.
167+
**Understanding `local_target_path`:**
168+
* If omitted, the download target is the current working directory (`.`) on your computer.
169+
* If provided, it specifies the local directory where items will be placed or the local filename if downloading a single file to a specific name. The tool will create this directory if it doesn't exist.
176170
177171
**Scenarios & Examples:**
178-
```bash
179-
esp32 download_all lib
180-
# Creates ./lib/ locally and copies contents of /lib from device into it.
181172
182-
esp32 download_all data my_backup/device_data
183-
# Creates ./my_backup/device_data/ locally and copies /data/* into it.
184-
```
173+
1. **Download a remote file to the current local directory:**
174+
```bash
175+
esp32 download /boot.py
176+
# Result: ./boot.py locally
177+
```
178+
2. **Download a remote file to a specific local directory, keeping its name:**
179+
```bash
180+
esp32 download /lib/utils.py my_local_lib
181+
# Result: ./my_local_lib/utils.py locally (my_local_lib/ created if needed)
182+
```
183+
3. **Download a remote file to a specific local path and name:** (mpremote behavior for `cp :remote_file local_file_path`)
184+
```bash
185+
esp32 download /data/sensor.dat backup/latest_sensor.dat
186+
# Result: ./backup/latest_sensor.dat locally
187+
```
188+
4. **Download a remote directory (e.g., `logs`) and its contents into the current local directory:**
189+
```bash
190+
esp32 download /logs
191+
# Result: ./logs/... locally (creates a 'logs' folder in CWD)
192+
```
193+
5. **Download a remote directory (e.g., `data`) and its contents into a specified local directory (`backup_data`):**
194+
```bash
195+
esp32 download /data backup_data
196+
# Result: ./backup_data/data/... locally
197+
```
198+
6. **Download the *contents* of a remote directory (e.g., `/app/`) into the current local directory:**
199+
```bash
200+
esp32 download /app/ .
201+
# Result: Files and subdirectories from /app/ on device are copied into ./ locally
202+
# Example: if /app/main.py and /app/gfx/img.png exist,
203+
# they become ./main.py and ./gfx/img.png
204+
```
205+
7. **Download the *contents* of a remote directory (e.g., `/lib/`) into a specified local directory (`local_libs_backup`):**
206+
```bash
207+
esp32 download /lib/ local_libs_backup
208+
# Result: Contents of /lib/ on device are copied into ./local_libs_backup/ locally
209+
# Example: if /lib/tool.py exists, it becomes ./local_libs_backup/tool.py
210+
```
211+
8. **Download the *contents* of the device's root directory into a local directory `full_backup`:**
212+
```bash
213+
esp32 download // full_backup
214+
# Result: All files and folders from device root copied into ./full_backup/
215+
```
185216
186217
### 4.5 Managing Remote Filesystem
187218
188219
* **`esp32 list [remote_directory]`** or **`esp32 ls [remote_directory]`**
189-
Lists files and directories on the ESP32.
190-
* `remote_directory` (optional): The directory to list. Defaults to the root (`/`).
220+
Lists files and directories on the ESP32. The listing is recursive from the given path.
221+
* `remote_directory` (optional): The directory to list (e.g., `/lib`). Defaults to the root (`/`), listing top-level items.
191222
192223
**Shorthand Usage:**
193224
```bash
@@ -208,25 +239,26 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
208239
* **`esp32 delete [remote_path_to_delete]`**
209240
Deletes a file or directory (recursively) on the ESP32.
210241
* `remote_path_to_delete` (optional): The file or directory to delete (e.g., `old_main.py`, `temp_files/`).
211-
* If omitted, the command will prompt for confirmation to **delete all contents of the root directory**. **Use with extreme caution!**
242+
* If omitted or set to `/`, the command will prompt for confirmation to **delete all contents of the root directory**. **Use with extreme caution!**
212243
213244
**Shorthand Usage:**
214245
```bash
215246
esp32 delete old_script.py
216247
esp32 delete my_module/
217248
esp32 delete # Prompts to wipe root
249+
esp32 delete / # Also prompts to wipe root
218250
```
219251
220252
### 4.6 Running Scripts
221253
222254
* **`esp32 run [script_name]`**
223255
Executes a MicroPython script that exists on the ESP32's filesystem.
224-
* `script_name` (optional): The path to the script on the device (e.g., `app.py`, `tests/run_tests.py`). Defaults to `main.py`.
256+
* `script_name` (optional): The path to the script on the device (e.g., `app.py`, `tests/run_tests.py`). Defaults to `main.py`. Path is relative to the device root.
225257
The script's output (and any errors) will be displayed in your terminal.
226258
227259
**Shorthand Usage:**
228260
```bash
229-
esp32 run
261+
esp32 run
230262
# Executes /main.py on device
231263
232264
esp32 run services/scanner.py
@@ -238,7 +270,7 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
238270
* **Connection Issues / Device Not Detected:**
239271
* Ensure the USB-C cable supports data transfer (not just charging).
240272
* Verify the correct COM port is selected (`esp32 devices`, `esp32 device <PORT>`).
241-
* For flashing or if the device is unresponsive, make sure it's in **bootloader mode**. See Section 4.2 or `docs/identify_board.md`.
273+
* For flashing or if the device is unresponsive, make sure it's in **bootloader mode**. See Section 4.2 or `docs_md/identify_board.md`.
242274
* Check if other serial terminal programs (Arduino IDE Serial Monitor, PuTTY, etc.) are holding the port open. Close them.
243275
244276
* **`esptool` or `mpremote` command not found:**
@@ -252,7 +284,7 @@ This command erases the ESP32-C3's flash and installs MicroPython firmware.
252284
```bash
253285
esp32 flash path/to/your_downloaded_firmware.bin
254286
```
255-
* After flashing, physically reset the device before testing.
287+
* After flashing, physically reset the device (unplug/replug or RST button) before testing.
256288
257289
* **Upload/Download/List commands fail with "No response or mpremote error":**
258290
* Ensure MicroPython is running correctly on the device. Try `esp32 device` to test basic connectivity.

0 commit comments

Comments
 (0)