Skip to content

Commit

Permalink
Merge pull request espressif#453 from espressif-abhikroy/component/co…
Browse files Browse the repository at this point in the history
…nsole_cmd_wifi

feat(console): Console for runtime wifi configuration
  • Loading branch information
espressif-abhikroy authored Dec 22, 2023
2 parents aadda22 + a532e76 commit cf845cc
Show file tree
Hide file tree
Showing 15 changed files with 481 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/console_cmd_wifi__build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "console_cmd_wifi: build-tests"

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]

jobs:
build_console_cmd_wifi:
if: contains(github.event.pull_request.labels.*.name, 'console') || github.event_name == 'push'
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.0"]
idf_target: ["esp32"]
test: [ { app: example, path: "components/console_cmd_wifi/examples" }]
runs-on: ubuntu-20.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
shell: bash
working-directory: ${{matrix.test.path}}
run: |
${IDF_PATH}/install.sh --enable-pytest
. ${IDF_PATH}/export.sh
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app
1 change: 1 addition & 0 deletions .github/workflows/publish-docs-component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ jobs:
components/console_simple_init;
components/console_cmd_ping;
components/console_cmd_ifconfig;
components/console_cmd_wifi;
namespace: "espressif"
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
13 changes: 12 additions & 1 deletion components/console_cmd_ifconfig/console_ifconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ static esp_netif_t *get_esp_netif_from_ifname(char *if_name)
char interface[10];

/* Get interface details and obtain the global IPv6 address */
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
#else
while ((esp_netif = esp_netif_next_unsafe(esp_netif)) != NULL) {
#endif
ret = esp_netif_get_netif_impl_name(esp_netif, interface);

if ((ESP_FAIL == ret) || (NULL == esp_netif)) {
Expand Down Expand Up @@ -212,8 +216,11 @@ static esp_err_t set_napt(char *if_name, bool state)

/* Get interface details and own global ipv6 address */
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
esp_netif = esp_netif_next(esp_netif);

#else
esp_netif = esp_netif_next_unsafe(esp_netif);
#endif
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
if ((ESP_FAIL == ret) || (NULL == esp_netif)) {
ESP_LOGE(TAG, "No interface available");
Expand Down Expand Up @@ -369,7 +376,11 @@ static esp_err_t ifcfg_print_op(netif_op_t *self, int argc, char *argv[], esp_ne

/* Get interface details and own global ipv6 address of all interfaces */
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
esp_netif = esp_netif_next(esp_netif);
#else
esp_netif = esp_netif_next_unsafe(esp_netif);
#endif
print_iface_details(esp_netif);
}

Expand Down
8 changes: 8 additions & 0 deletions components/console_cmd_wifi/.cz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
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.0
version_files:
- idf_component.yml
7 changes: 7 additions & 0 deletions components/console_cmd_wifi/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

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

### Features

- Console for runtime wifi configuration ([194d1179](https://github.com/espressif/esp-protocols/commit/194d1179))
4 changes: 4 additions & 0 deletions components/console_cmd_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
idf_component_register(SRCS "console_wifi.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_netif console esp_wifi
WHOLE_ARCHIVE)
44 changes: 44 additions & 0 deletions components/console_cmd_wifi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Console command wifi
The component offers a console with a command that enables runtime wifi configuration for any example project.

## API

### Steps to enable console in an example code:
1. Add this component to your project using ```idf.py add-dependency``` command.
2. In the main file of the example, add the following line:
```c
#include "console_wifi.h"
```
3. Ensure esp-netif and NVS flash is initialized and default event loop is created in your app_main():
```c
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_err_t ret = nvs_flash_init(); //Initialize NVS
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
```
4. In your app_main() function, add the following line as the last line:
```c
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console

// Register all plugin command added to your project
ESP_ERROR_CHECK(console_cmd_all_register());

// To register only wifi command skip calling console_cmd_all_register()
ESP_ERROR_CHECK(console_cmd_wifi_register());

ESP_ERROR_CHECK(console_cmd_start()); // Start console
```

## 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.
Loading

0 comments on commit cf845cc

Please sign in to comment.