Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 79dfd9d

Browse files
committed
Add AP & STA Mode
1 parent 1e490ea commit 79dfd9d

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ idf.py flash monitor
4242

4343
- WIFI_CONNECT
4444
Select the Wifi connection method from the following:
45-
Connect to Wifi using AP mode and STA mode at the same time.
45+
Connect to Wifi using AP mode.
46+
Connect to Wifi using STA mode.
4647
Connect to Wifi using APSTA mode.
4748
- AP_WIFI_SSID
4849
WiFi SSID of AP mode
@@ -61,7 +62,12 @@ idf.py flash monitor
6162

6263
![config-main](https://user-images.githubusercontent.com/6020549/101855573-0090d100-3ba7-11eb-923f-b48a4c937085.jpg)
6364

64-
![config-app-1](https://user-images.githubusercontent.com/6020549/101855693-32a23300-3ba7-11eb-9f99-cbb41338827b.jpg)
65+
- AP Mode
66+
![config-ap](https://user-images.githubusercontent.com/6020549/107764961-600c8800-6d74-11eb-8353-9293c5927dcc.jpg)
6567

66-
![config-app-2](https://user-images.githubusercontent.com/6020549/101855700-35048d00-3ba7-11eb-9c18-d47be105632b.jpg)
68+
- STA Mode
69+
![config-sta](https://user-images.githubusercontent.com/6020549/107764963-613db500-6d74-11eb-80c5-d8de7d933b7d.jpg)
70+
71+
- APSTA Mode
72+
![config-apsta](https://user-images.githubusercontent.com/6020549/107764962-613db500-6d74-11eb-9ab4-09c3dcce00bd.jpg)
6773

main/Kconfig.projbuild

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,65 @@ menu "Application Configuration"
55
default WIFI_CONNECT_APSTA
66
help
77
Select Wifi connection.
8-
config WIFI_CONNECT_AP_PLUS_STA
9-
bool "Connect to Wifi using AP mode and STA mode at the same time"
8+
config WIFI_CONNECT_AP
9+
bool "Connect to Wifi using AP mode."
10+
config WIFI_CONNECT_STA
11+
bool "Connect to Wifi using STA mode."
1012
config WIFI_CONNECT_APSTA
1113
bool "Connect to Wifi using APSTA mode"
1214
endchoice
1315

16+
comment "for WiFi AP Setting"
17+
depends on WIFI_CONNECT_AP || WIFI_CONNECT_APSTA
18+
1419
config AP_WIFI_SSID
20+
depends on WIFI_CONNECT_AP || WIFI_CONNECT_APSTA
1521
string "WiFi SSID of AP mode"
1622
default "ap-ssid"
1723
help
1824
SSID (network name) for the example to connect to.
1925

2026
config AP_WIFI_PASSWORD
27+
depends on WIFI_CONNECT_AP || WIFI_CONNECT_APSTA
2128
string "WiFi Password of AP mode"
2229
default "ap-password"
2330
help
2431
WiFi password (WPA or WPA2) for the example to use.
2532

2633
config AP_WIFI_CHANNEL
34+
depends on WIFI_CONNECT_AP || WIFI_CONNECT_APSTA
2735
int "WiFi Channel of AP mode"
2836
range 1 13
2937
default 1
3038
help
3139
WiFi channel (network channel) for the example to use.
3240

3341
config AP_MAX_STA_CONN
42+
depends on WIFI_CONNECT_AP || WIFI_CONNECT_APSTA
3443
int "Maximal STA connections of AP mode"
3544
default 4
3645
help
3746
Max number of the STA connects to AP.
3847

48+
comment "for WiFi STA Setting"
49+
depends on WIFI_CONNECT_STA || WIFI_CONNECT_APSTA
50+
3951
config STA_WIFI_SSID
52+
depends on WIFI_CONNECT_STA || WIFI_CONNECT_APSTA
4053
string "WiFi SSID of STA mode"
4154
default "sta-ssid"
4255
help
4356
SSID (network name) for the example to connect to.
4457

4558
config STA_WIFI_PASSWORD
59+
depends on WIFI_CONNECT_STA || WIFI_CONNECT_APSTA
4660
string "WiFi Password of STA mode"
4761
default "sta-password"
4862
help
4963
WiFi password (WPA or WPA2) for the example to use.
5064

5165
config STA_CONNECT_TIMEOUT
66+
depends on WIFI_CONNECT_STA || WIFI_CONNECT_APSTA
5267
int "Connect timeout of STA mode"
5368
default 5
5469
help

main/main.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void initialise_wifi(void)
5858
initialized = true;
5959
}
6060

61-
#if CONFIG_WIFI_CONNECT_AP_PLUS_STA
61+
#if CONFIG_WIFI_CONNECT_AP
6262
static bool wifi_ap(void)
6363
{
6464
wifi_config_t wifi_config = { 0 };
@@ -81,7 +81,10 @@ static bool wifi_ap(void)
8181
CONFIG_AP_WIFI_SSID, CONFIG_AP_WIFI_PASSWORD, CONFIG_AP_WIFI_CHANNEL);
8282
return ESP_OK;
8383
}
84+
#endif
85+
8486

87+
#if CONFIG_WIFI_CONNECT_STA
8588
static bool wifi_sta(int timeout_ms)
8689
{
8790
wifi_config_t wifi_config = { 0 };
@@ -159,15 +162,14 @@ void app_main()
159162

160163
initialise_wifi();
161164

162-
#if CONFIG_WIFI_CONNECT_AP_PLUS_STA
163-
ESP_LOGW(TAG, "Start wifi_ap");
165+
#if CONFIG_WIFI_CONNECT_AP
166+
ESP_LOGW(TAG, "Start AP Mode");
164167
wifi_ap();
165-
ESP_LOGW(TAG, "Start wifi_sta");
168+
#elif CONFIG_WIFI_CONNECT_STA
169+
ESP_LOGW(TAG, "Start STA Mode");
166170
wifi_sta(CONFIG_STA_CONNECT_TIMEOUT*1000);
167-
#endif
168-
169-
#if CONFIG_WIFI_CONNECT_APSTA
170-
ESP_LOGW(TAG, "Start wifi_apsta");
171+
#elif CONFIG_WIFI_CONNECT_APSTA
172+
ESP_LOGW(TAG, "Start APSTA Mode");
171173
wifi_apsta(CONFIG_STA_CONNECT_TIMEOUT*1000);
172174
#endif
173175
}

0 commit comments

Comments
 (0)