ethernet_example_main.c 2.4 KB

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