Skip to content

Commit 3d8f1d6

Browse files
feat(console): Console for runtime wifi configuration
1 parent 82c2cf8 commit 3d8f1d6

File tree

14 files changed

+474
-1
lines changed

14 files changed

+474
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "console_cmd_wifi: build-tests"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types: [opened, synchronize, reopened, labeled]
9+
10+
jobs:
11+
build_console_cmd_wifi:
12+
if: contains(github.event.pull_request.labels.*.name, 'console') || github.event_name == 'push'
13+
name: Build
14+
strategy:
15+
matrix:
16+
idf_ver: ["latest", "release-v5.0"]
17+
idf_target: ["esp32"]
18+
test: [ { app: example, path: "components/console_cmd_wifi/examples" }]
19+
runs-on: ubuntu-20.04
20+
container: espressif/idf:${{ matrix.idf_ver }}
21+
steps:
22+
- name: Checkout esp-protocols
23+
uses: actions/checkout@v3
24+
with:
25+
submodules: recursive
26+
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
27+
shell: bash
28+
working-directory: ${{matrix.test.path}}
29+
run: |
30+
${IDF_PATH}/install.sh --enable-pytest
31+
. ${IDF_PATH}/export.sh
32+
python $IDF_PATH/tools/ci/ci_build_apps.py . --target ${{ matrix.idf_target }} -vv --preserve-all --pytest-app

.github/workflows/publish-docs-component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ jobs:
9696
components/console_simple_init;
9797
components/console_cmd_ping;
9898
components/console_cmd_ifconfig;
99+
components/console_cmd_wifi;
99100
namespace: "espressif"
100101
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

components/console_cmd_ifconfig/console_ifconfig.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ static esp_netif_t *get_esp_netif_from_ifname(char *if_name)
9999
char interface[10];
100100

101101
/* Get interface details and obtain the global IPv6 address */
102+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
102103
while ((esp_netif = esp_netif_next(esp_netif)) != NULL) {
104+
#else
105+
while ((esp_netif = esp_netif_next_unsafe(esp_netif)) != NULL) {
106+
#endif
103107
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
104108

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

213217
/* Get interface details and own global ipv6 address */
214218
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
219+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
215220
esp_netif = esp_netif_next(esp_netif);
216-
221+
#else
222+
esp_netif = esp_netif_next_unsafe(esp_netif);
223+
#endif
217224
ret = esp_netif_get_netif_impl_name(esp_netif, interface);
218225
if ((ESP_FAIL == ret) || (NULL == esp_netif)) {
219226
ESP_LOGE(TAG, "No interface available");
@@ -369,7 +376,11 @@ static esp_err_t ifcfg_print_op(netif_op_t *self, int argc, char *argv[], esp_ne
369376

370377
/* Get interface details and own global ipv6 address of all interfaces */
371378
for (int i = 0; i < esp_netif_get_nr_of_ifs(); ++i) {
379+
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)
372380
esp_netif = esp_netif_next(esp_netif);
381+
#else
382+
esp_netif = esp_netif_next_unsafe(esp_netif);
383+
#endif
373384
print_iface_details(esp_netif);
374385
}
375386

components/console_cmd_wifi/.cz.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
commitizen:
3+
bump_message: 'bump(console): $current_version -> $new_version'
4+
pre_bump_hooks: python ../../ci/changelog.py console_cmd_wifi
5+
tag_format: console_cmd_wifi-v$version
6+
version: 0.0.9
7+
version_files:
8+
- idf_component.yml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(SRCS "console_wifi.c"
2+
INCLUDE_DIRS "."
3+
PRIV_REQUIRES esp_netif console esp_wifi
4+
WHOLE_ARCHIVE)

components/console_cmd_wifi/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Console command wifi
2+
The component offers a console with a command that enables runtime wifi configuration for any example project.
3+
4+
## API
5+
6+
### Steps to enable console in an example code:
7+
1. Add this component to your project using ```idf.py add-dependency``` command.
8+
2. In the main file of the example, add the following line:
9+
```c
10+
#include "console_wifi.h"
11+
```
12+
3. Ensure esp-netif and NVS flash is initialized and default event loop is created in your app_main():
13+
```c
14+
ESP_ERROR_CHECK(esp_netif_init());
15+
ESP_ERROR_CHECK(esp_event_loop_create_default());
16+
esp_err_t ret = nvs_flash_init(); //Initialize NVS
17+
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
18+
ESP_ERROR_CHECK(nvs_flash_erase());
19+
ret = nvs_flash_init();
20+
}
21+
ESP_ERROR_CHECK(ret);
22+
```
23+
4. In your app_main() function, add the following line as the last line:
24+
```c
25+
ESP_ERROR_CHECK(console_cmd_init()); // Initialize console
26+
27+
// Register all plugin command added to your project
28+
ESP_ERROR_CHECK(console_cmd_all_register());
29+
30+
// To register only wifi command skip calling console_cmd_all_register()
31+
ESP_ERROR_CHECK(console_cmd_wifi_register());
32+
33+
ESP_ERROR_CHECK(console_cmd_start()); // Start console
34+
```
35+
36+
## Suported command:
37+
38+
### wifi:
39+
* ```wifi help```: Prints the help text for all wifi commands
40+
* ```wifi show network```: Scans and displays upto 10 available wifi networks.
41+
* ```wifi show sta```: Shows the details of wifi station.
42+
* ```wifi sta join <network ssid> <password>```: Station joins the given wifi network.
43+
* ```wifi sta join <network ssid>```: Station joins the given unsecured wifi network.
44+
* ```wifi sta leave```: Station leaves the wifi network.

0 commit comments

Comments
 (0)