1 /* Ethernet iperf example
2
3 This example code is in the Public Domain (or CC0 licensed, at your option.)
4
5 Unless required by applicable law or agreed to in writing, this
6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7 CONDITIONS OF ANY KIND, either express or implied.
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include "sdkconfig.h"
13 #include "esp_log.h"
14 #include "esp_console.h"
15 #include "esp_vfs_fat.h"
16 #include "cmd_system.h"
17 #include "cmd_ethernet.h"
18
19 static const char *TAG = "eth_example";
20
21 #if CONFIG_EXAMPLE_STORE_HISTORY
22
23 #define MOUNT_PATH "/data"
24 #define HISTORY_PATH MOUNT_PATH "/history.txt"
25
initialize_filesystem(void)26 static void initialize_filesystem(void)
27 {
28 static wl_handle_t wl_handle;
29 const esp_vfs_fat_mount_config_t mount_config = {
30 .max_files = 4,
31 .format_if_mount_failed = true
32 };
33 esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
34 if (err != ESP_OK) {
35 ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
36 return;
37 }
38 }
39 #endif // CONFIG_EXAMPLE_STORE_HISTORY
40
app_main(void)41 void app_main(void)
42 {
43 esp_console_repl_t *repl = NULL;
44 esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
45 esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
46 #if CONFIG_EXAMPLE_STORE_HISTORY
47 initialize_filesystem();
48 repl_config.history_save_path = HISTORY_PATH;
49 #endif
50 repl_config.prompt = "iperf>";
51 // init console REPL environment
52 ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
53
54 /* Register commands */
55 register_system_common();
56 register_ethernet();
57
58 printf("\n =======================================================\n");
59 printf(" | Steps to Test Ethernet Bandwidth |\n");
60 printf(" | |\n");
61 printf(" | 1. Enter 'help', check all supported commands |\n");
62 printf(" | 2. Wait ESP32 to get IP from DHCP |\n");
63 printf(" | 3. Enter 'ethernet info', optional |\n");
64 printf(" | 4. Server: 'iperf -u -s -i 3' |\n");
65 printf(" | 5. Client: 'iperf -u -c SERVER_IP -t 60 -i 3' |\n");
66 printf(" | |\n");
67 printf(" =======================================================\n\n");
68
69 // start console REPL
70 ESP_ERROR_CHECK(esp_console_start_repl(repl));
71 }
72