Skip to content

Commit

Permalink
Merge pull request #513 from espressif-abhikroy/component/console_cmd…
Browse files Browse the repository at this point in the history
…_wifi

feat(console): wifi commands updates
  • Loading branch information
espressif-abhikroy authored Jun 11, 2024
2 parents 7f248bd + 5d43f96 commit b2272b4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/console_cmd_wifi/.cz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ commitizen:
bump_message: 'bump(console): $current_version -> $new_version'
pre_bump_hooks: python ../../ci/changelog.py console_cmd_wifi
tag_format: console_cmd_wifi-v$version
version: 1.0.1
version: 1.1.0
version_files:
- idf_component.yml
6 changes: 6 additions & 0 deletions components/console_cmd_wifi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.1.0](https://github.com/espressif/esp-protocols/commits/console_cmd_wifi-v1.1.0)

### Features

- Added support to join pre-configured network ([bdbf16c1](https://github.com/espressif/esp-protocols/commit/bdbf16c1))

## [1.0.1](https://github.com/espressif/esp-protocols/commits/console_cmd_wifi-v1.0.1)

### Features
Expand Down
10 changes: 7 additions & 3 deletions components/console_cmd_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
idf_component_register(SRCS "console_wifi.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_netif console esp_wifi
WHOLE_ARCHIVE)
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) to connect to.

config WIFI_CMD_NETWORK_PASSWORD
string "WiFi Password"
default "mypassword"
help
WiFi password (WPA or WPA2) 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 the pre-configured wifi network.
wifi sta leave: Station leaves the wifi network.
```
18 changes: 13 additions & 5 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 the pre-configured 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 @@ -162,7 +165,6 @@ static esp_err_t wifi_show_op(wifi_op_t *self, int argc, char *argv[])
ESP_LOGI(TAG, "Showing Joind AP details:");
ESP_LOGI(TAG, "*************************");
ESP_LOGI(TAG, "SSID: %s", wifi_config.sta.ssid);
ESP_LOGI(TAG, "Password: %s", wifi_config.sta.password);
ESP_LOGI(TAG, "Channel: %d", wifi_config.sta.channel);
ESP_LOGI(TAG, "bssid: %02x:%02x:%02x:%02x:%02x:%02x", wifi_config.sta.bssid[0],
wifi_config.sta.bssid[1], wifi_config.sta.bssid[2], wifi_config.sta.bssid[3],
Expand All @@ -184,7 +186,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) {
strlcpy((char *) wifi_config.sta.ssid, CONFIG_WIFI_CMD_NETWORK_SSID, sizeof(wifi_config.sta.ssid));
strlcpy((char *) wifi_config.sta.password, CONFIG_WIFI_CMD_NETWORK_PASSWORD, sizeof(wifi_config.sta.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 +268,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
2 changes: 1 addition & 1 deletion components/console_cmd_wifi/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1.0.1
version: 1.1.0
url: https://github.com/espressif/esp-protocols/tree/master/components/console_cmd_wifi
description: The component offers a console that enables runtime wifi configuration and monitoring.
dependencies:
Expand Down
File renamed without changes.

0 comments on commit b2272b4

Please sign in to comment.