Skip to content

Commit

Permalink
feat(console): Moved wifi commands from idf examples
Browse files Browse the repository at this point in the history
  • Loading branch information
espressif-abhikroy committed Feb 28, 2024
1 parent a363bee commit 865d090
Show file tree
Hide file tree
Showing 10 changed files with 2,009 additions and 13 deletions.
13 changes: 10 additions & 3 deletions components/console_cmd_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
idf_component_register(SRCS "console_wifi.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_netif console esp_wifi
WHOLE_ARCHIVE)
"wifi_cmd.c"
"wifi_stats.c"
"wifi_twt.c"
INCLUDE_DIRS "include"
REQUIRES lwip
PRIV_REQUIRES esp_netif console esp_wifi esp_timer)

if(CONFIG_WIFI_CMD_AUTO_REGISTRATION)
target_link_libraries(${COMPONENT_LIB} "-u console_cmd_wifi_register")
endif()
22 changes: 22 additions & 0 deletions components/console_cmd_wifi/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
menu "Wifi command Configuration"

config WIFI_CMD_AUTO_REGISTRATION
bool "Enable Console command wifi Auto-registration"
default y
help
Enabling this allows for the autoregistration of the wifi command.

config WIFI_CMD_NETWORK_SSID
string "WiFi SSID"
default "myssid"
help
SSID (network name) for the example to connect to.

config WIFI_CMD_NETWORK_PASSWORD
string "WiFi Password"
default "mypassword"
help
WiFi password (WPA or WPA2) for the example to use.
Can be left blank if the network has no security set.

endmenu
16 changes: 10 additions & 6 deletions components/console_cmd_wifi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ The component offers a console with a command that enables runtime wifi configur
ESP_ERROR_CHECK(console_cmd_start()); // Start console
```

Note: Auto-registration of a specific plugin command can be disabled from menuconfig.

## Suported command:

### wifi:
* ```wifi help```: Prints the help text for all wifi commands
* ```wifi show network```: Scans and displays upto 10 available wifi networks.
* ```wifi show sta```: Shows the details of wifi station.
* ```wifi sta join <network ssid> <password>```: Station joins the given wifi network.
* ```wifi sta join <network ssid>```: Station joins the given unsecured wifi network.
* ```wifi sta leave```: Station leaves the wifi network.
```
wifi help: Prints the help text for all wifi commands
wifi show network/sta: Scans and displays all available wifi APs./ Shows the details of wifi station.
wifi sta join <network ssid> <password>: Station joins the given wifi network.
wifi sta join <network ssid>: Station joins the given unsecured wifi network.
wifi sta join: Station joins pre-configured the wifi network.
wifi sta leave: Station leaves the wifi network.
```
17 changes: 13 additions & 4 deletions components/console_cmd_wifi/console_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#define DEFAULT_SCAN_LIST_SIZE 10

#if CONFIG_WIFI_CMD_AUTO_REGISTRATION
/**
* Static registration of this plugin is achieved by defining the plugin description
* structure and placing it into .console_cmd_desc section.
Expand All @@ -30,6 +31,7 @@ static const console_cmd_plugin_desc_t __attribute__((section(".console_cmd_desc
.name = "console_cmd_wifi",
.plugin_regd_fn = &console_cmd_wifi_register
};
#endif

typedef struct wifi_op_t {
char *name;
Expand All @@ -55,8 +57,9 @@ static const int CONNECTED_BIT = BIT1;
static wifi_op_t cmd_list[] = {
{.name = "help", .operation = wifi_help_op, .arg_cnt = 2, .start_index = 1, .help = "wifi help: Prints the help text for all wifi commands"},
{.name = "show", .operation = wifi_show_op, .arg_cnt = 3, .start_index = 1, .help = "wifi show network/sta: Scans and displays all available wifi APs./ Shows the details of wifi station."},
{.name = "join", .operation = wifi_sta_join_op, .arg_cnt = 4, .start_index = 2, .help = "wifi sta join <network ssid> <password>: Station joins the given wifi network."},
{.name = "join", .operation = wifi_sta_join_op, .arg_cnt = 5, .start_index = 2, .help = "wifi sta join <network ssid>: Station joins the given unsecured wifi network."},
{.name = "join", .operation = wifi_sta_join_op, .arg_cnt = 5, .start_index = 2, .help = "wifi sta join <network ssid> <password>: Station joins the given wifi network."},
{.name = "join", .operation = wifi_sta_join_op, .arg_cnt = 4, .start_index = 2, .help = "wifi sta join <network ssid>: Station joins the given unsecured wifi network."},
{.name = "join", .operation = wifi_sta_join_op, .arg_cnt = 3, .start_index = 2, .help = "wifi sta join: Station joins pre-configured the wifi network."},
{.name = "leave", .operation = wifi_sta_leave_op, .arg_cnt = 3, .start_index = 2, .help = "wifi sta leave: Station leaves the wifi network."},
};

Expand Down Expand Up @@ -184,7 +187,13 @@ static esp_err_t wifi_sta_join_op(wifi_op_t *self, int argc, char *argv[])
return ESP_FAIL;
}

strlcpy((char *) wifi_config.sta.ssid, argv[self->start_index + 1], sizeof(wifi_config.sta.ssid));
if (self->arg_cnt == 3) {
strcpy((char *) wifi_config.sta.ssid, CONFIG_WIFI_CMD_NETWORK_SSID);
strcpy((char *) wifi_config.sta.password, CONFIG_WIFI_CMD_NETWORK_PASSWORD);
} else {
strlcpy((char *) wifi_config.sta.ssid, argv[self->start_index + 1], sizeof(wifi_config.sta.ssid));
}

if (self->arg_cnt == 5) {
strlcpy((char *) wifi_config.sta.password, argv[self->start_index + 2], sizeof(wifi_config.sta.password));
}
Expand Down Expand Up @@ -260,7 +269,7 @@ static esp_err_t do_cmd_wifi(int argc, char **argv)
*/
esp_err_t console_cmd_wifi_register(void)
{
esp_err_t ret;
esp_err_t ret = ESP_OK;
esp_console_cmd_t command = {
.command = "wifi",
.help = "Command for wifi configuration and monitoring\n For more info run 'wifi help'",
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions components/console_cmd_wifi/include/wifi_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif


void register_wifi_cmd(void);
void register_wifi_itwt(void);
void register_wifi_stats(void);


#ifdef __cplusplus
}
#endif
26 changes: 26 additions & 0 deletions components/console_cmd_wifi/include/wifi_stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif


#if CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS || CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS

int wifi_cmd_get_tx_statistics(int argc, char **argv);
int wifi_cmd_clr_tx_statistics(int argc, char **argv);

int wifi_cmd_get_rx_statistics(int argc, char **argv);
int wifi_cmd_clr_rx_statistics(int argc, char **argv);

#endif

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 865d090

Please sign in to comment.