OVMS3-idf/examples/ethernet/iperf/main/ethernet_example_main.c
suda-morris 75cadc2e41 console: simplify examples
1. simplify console examples
2. add "quit" command
3. support console command overwrite
4. add API reference
2020-02-07 20:15:06 +08:00

69 lines
2.3 KiB
C

/* Ethernet iperf example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_console.h"
#include "esp_vfs_fat.h"
#include "cmd_system.h"
#include "cmd_ethernet.h"
static const char *TAG = "eth_example";
#if CONFIG_EXAMPLE_STORE_HISTORY
#define MOUNT_PATH "/data"
#define HISTORY_PATH MOUNT_PATH "/history.txt"
static void initialize_filesystem(void)
{
static wl_handle_t wl_handle;
const esp_vfs_fat_mount_config_t mount_config = {
.max_files = 4,
.format_if_mount_failed = true
};
esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err));
return;
}
}
#endif // CONFIG_EXAMPLE_STORE_HISTORY
void app_main(void)
{
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
#if CONFIG_EXAMPLE_STORE_HISTORY
initialize_filesystem();
repl_config.history_save_path = HISTORY_PATH;
#endif
// initialize console REPL environment
ESP_ERROR_CHECK(esp_console_repl_init(&repl_config));
/* Register commands */
register_system();
register_ethernet();
printf("\n =======================================================\n");
printf(" | Steps to Test Ethernet Bandwidth |\n");
printf(" | |\n");
printf(" | 1. Enter 'help', check all supported commands |\n");
printf(" | 2. Wait ESP32 to get IP from DHCP |\n");
printf(" | 3. Enter 'ethernet info', optional |\n");
printf(" | 4. Server: 'iperf -u -s -i 3' |\n");
printf(" | 5. Client: 'iperf -u -c SERVER_IP -t 60 -i 3' |\n");
printf(" | |\n");
printf(" =======================================================\n\n");
// start console REPL
ESP_ERROR_CHECK(esp_console_repl_start());
}