Skip to content

Commit

Permalink
feat(ESPAT-2082): Added a http_get_to_fatfs example
Browse files Browse the repository at this point in the history
  • Loading branch information
ustccw committed Oct 21, 2024
1 parent 102d512 commit c628a89
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 0 deletions.
35 changes: 35 additions & 0 deletions components/at/include/esp_at_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,39 @@ const uint8_t* esp_at_get_current_cmd_name(void);
*/
int32_t esp_at_get_core_version(char *buffer, uint32_t size);

/**
* @brief Mount FATFS partition
*
* @note if you want to use FATFS, you should enable "AT FS command support" in menuconfig first.
* @note esp-at uses a fixed partition for the filesystem, which defined in esp-at/module_config/<your_module_config>/at_customize.csv,
* and uses a fixed mount point "/fatfs".
* @note when using FATFS, you should call this function to mount the partition first,
* and call at_fatfs_unmount() to unmount the partition when you don't need it.
*
* @return
* - true : succeed
* - false : fail
*/
bool at_fatfs_mount(void);

/**
* @brief Unmount FATFS partition
*
* @return
* - true : succeed
* - false : fail
*/
bool at_fatfs_unmount(void);

/**
* @brief Check if the string is NULL
*
* @param str: the string to be checked
*
* @return
* - true : the string is NULL
* - false : the string is not NULL
*/
bool at_str_is_null(uint8_t *str);

void at_handle_result_code(esp_at_result_code_string_index code, void *pbuf);
14 changes: 14 additions & 0 deletions examples/at_http_get_to_fatfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

file(GLOB_RECURSE srcs *.c)

set(includes "include")

# Add more required components you need here, separated by spaces
set(require_components at freertos nvs_flash)

idf_component_register(
SRCS ${srcs}
INCLUDE_DIRS ${includes}
REQUIRES ${require_components})

target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_at_custom_cmd_register")
43 changes: 43 additions & 0 deletions examples/at_http_get_to_fatfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Usage
1. Add this `at_http_get_to_fatfs` component into the build system of esp-at project.

- Linux or macOS
```
export AT_CUSTOM_COMPONENTS=(path_of_at_custom_cmd)
```

- Windows
```
set AT_CUSTOM_COMPONENTS=(path_of_at_custom_cmd)
```

Notes:
- You need to replace (path_of_at_custom_cmd) with your real absolute path of your `at_custom_cmd` directory.
- You can specify multiple components. For example: `export AT_CUSTOM_COMPONENTS="~/prefix/my_path1 ~/prefix/my_path2"`.

2. Compile your firmware according to the [Compile ESP-AT Project](https://docs.espressif.com/projects/esp-at/en/latest/esp32/Compile_and_Develop/How_to_clone_project_and_compile_it.html#compile-esp-at-project-locally) guide.

3. Send a new AT command based on your situation.

The new command format is:
```
AT+HTTPGET_TO_FS=<"dst_path">,<url_len>
```
where:
- <"dst_path">: Specify the destination path where the file will be stored on the filesystem after the HTTP GET request is successfully executed.
- <url_len>: URL length. Maximum: 8192 bytes.

For example: url is "http://192.168.200.249:8080/a.bin", and you want to save it to `foo.bin`.
```
AT+HTTPGET_TO_FS="foo.bin",33
// then input http://192.168.200.249:8080/a.bin
```

4. Check the file content

Please send [AT+FS](https://docs.espressif.com/projects/esp-at/en/latest/esp32/AT_Command_Set/FS_AT_Commands.html#at-fs-filesystem-operations) command to read the data of your <"dst_path">.

For example: read 100 bytes from offset 0 of `foo.bin` file.
```
AT+FS=0,2,"foo.bin",0,100
```
Loading

0 comments on commit c628a89

Please sign in to comment.