1 /* Wi-Fi 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 <errno.h>
11 #include <string.h>
12 #include "esp_wifi.h"
13 #include "esp_log.h"
14 #include "esp_err.h"
15 #include "nvs_flash.h"
16 #include "esp_console.h"
17 #include "cmd_decl.h"
18 
app_main(void)19 void app_main(void)
20 {
21     esp_err_t ret = nvs_flash_init();
22     if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
23         ESP_ERROR_CHECK(nvs_flash_erase());
24         ret = nvs_flash_init();
25     }
26     ESP_ERROR_CHECK( ret );
27 
28     initialise_wifi();
29 
30     esp_console_repl_t *repl = NULL;
31     esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
32     repl_config.prompt = "iperf>";
33 
34     // init console REPL environment
35 #if CONFIG_ESP_CONSOLE_UART
36     esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
37     ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
38 #elif CONFIG_ESP_CONSOLE_USB_CDC
39     esp_console_dev_usb_cdc_config_t cdc_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
40     ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&cdc_config, &repl_config, &repl));
41 #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
42     esp_console_dev_usb_serial_jtag_config_t usbjtag_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT();
43     ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&usbjtag_config, &repl_config, &repl));
44 #endif
45 
46     /* Register commands */
47     register_system();
48     register_wifi();
49 
50     printf("\n ==================================================\n");
51     printf(" |       Steps to test WiFi throughput            |\n");
52     printf(" |                                                |\n");
53     printf(" |  1. Print 'help' to gain overview of commands  |\n");
54     printf(" |  2. Configure device to station or soft-AP     |\n");
55     printf(" |  3. Setup WiFi connection                      |\n");
56     printf(" |  4. Run iperf to test UDP/TCP RX/TX throughput |\n");
57     printf(" |                                                |\n");
58     printf(" =================================================\n\n");
59 
60     // start console REPL
61     ESP_ERROR_CHECK(esp_console_start_repl(repl));
62 }
63