From d967506b199bad18ca1060e7307d07f6c797d45a Mon Sep 17 00:00:00 2001 From: XiaochaoGONG Date: Mon, 20 Apr 2020 14:36:17 +0800 Subject: [PATCH] add ap channel config --- .../single_chip/camera_web_server/main/Kconfig.projbuild | 6 ++++++ examples/single_chip/camera_web_server/main/app_wifi.c | 9 ++++++++- .../recognition_solution/main/Kconfig.projbuild | 6 ++++++ .../single_chip/recognition_solution/main/app_wifi.c | 6 ++++++ .../recognition_wechat/main/Kconfig.projbuild | 6 ++++++ examples/single_chip/recognition_wechat/main/app_wifi.c | 6 ++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/single_chip/camera_web_server/main/Kconfig.projbuild b/examples/single_chip/camera_web_server/main/Kconfig.projbuild index 2a86b44..f49d8ff 100644 --- a/examples/single_chip/camera_web_server/main/Kconfig.projbuild +++ b/examples/single_chip/camera_web_server/main/Kconfig.projbuild @@ -31,6 +31,12 @@ config ESP_WIFI_AP_PASSWORD help AP password for WPA2 or empty for Open. +config ESP_WIFI_AP_CHANNEL + string "WiFi AP Channel" + default "" + help + AP channel for better connection performance. + config SERVER_IP string "WiFi AP IP Address" default "192.168.4.1" diff --git a/examples/single_chip/camera_web_server/main/app_wifi.c b/examples/single_chip/camera_web_server/main/app_wifi.c index d7d719a..df65f85 100644 --- a/examples/single_chip/camera_web_server/main/app_wifi.c +++ b/examples/single_chip/camera_web_server/main/app_wifi.c @@ -45,7 +45,9 @@ #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY #define EXAMPLE_ESP_WIFI_AP_SSID CONFIG_ESP_WIFI_AP_SSID #define EXAMPLE_ESP_WIFI_AP_PASS CONFIG_ESP_WIFI_AP_PASSWORD +#define EXAMPLE_MAX_STA_CONN CONFIG_MAX_STA_CONN #define EXAMPLE_IP_ADDR CONFIG_SERVER_IP +#define EXAMPLE_ESP_WIFI_AP_CHANNEL CONFIG_ESP_WIFI_AP_CHANNEL static const char *TAG = "camera wifi"; @@ -108,11 +110,16 @@ void wifi_init_softap() snprintf((char*)wifi_config.ap.ssid, 32, "%s", EXAMPLE_ESP_WIFI_AP_SSID); wifi_config.ap.ssid_len = strlen((char*)wifi_config.ap.ssid); snprintf((char*)wifi_config.ap.password, 64, "%s", EXAMPLE_ESP_WIFI_AP_PASS); - wifi_config.ap.max_connection = 1; + wifi_config.ap.max_connection = EXAMPLE_MAX_STA_CONN; wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK; if (strlen(EXAMPLE_ESP_WIFI_AP_PASS) == 0) { wifi_config.ap.authmode = WIFI_AUTH_OPEN; } + if (strlen(EXAMPLE_ESP_WIFI_AP_CHANNEL)) { + int channel; + sscanf(EXAMPLE_ESP_WIFI_AP_CHANNEL, "%d", &channel); + wifi_config.ap.channel = channel; + } ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config)); diff --git a/examples/single_chip/recognition_solution/main/Kconfig.projbuild b/examples/single_chip/recognition_solution/main/Kconfig.projbuild index eae51b5..8acf12f 100644 --- a/examples/single_chip/recognition_solution/main/Kconfig.projbuild +++ b/examples/single_chip/recognition_solution/main/Kconfig.projbuild @@ -18,6 +18,12 @@ config MAX_STA_CONN help Max number of the STA connects to AP. +config ESP_WIFI_AP_CHANNEL + string "WiFi AP Channel" + default "" + help + AP channel for better connection performance. + config SERVER_IP string "IP address of server" default "192.168.4.1" diff --git a/examples/single_chip/recognition_solution/main/app_wifi.c b/examples/single_chip/recognition_solution/main/app_wifi.c index 9e56a68..58b4d1a 100644 --- a/examples/single_chip/recognition_solution/main/app_wifi.c +++ b/examples/single_chip/recognition_solution/main/app_wifi.c @@ -41,6 +41,7 @@ static const char *TAG = "app_wifi"; #define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD #define EXAMPLE_MAX_STA_CONN CONFIG_MAX_STA_CONN #define EXAMPLE_IP_ADDR CONFIG_SERVER_IP +#define EXAMPLE_ESP_WIFI_AP_CHANNEL CONFIG_ESP_WIFI_AP_CHANNEL static esp_err_t event_handler(void *ctx, system_event_t *event) {/*{{{*/ @@ -112,6 +113,11 @@ static void wifi_init_softap() wifi_config.ap.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID); wifi_config.ap.max_connection = EXAMPLE_MAX_STA_CONN; wifi_config.ap.authmode = WIFI_AUTH_WPA_WPA2_PSK; + if (strlen(EXAMPLE_ESP_WIFI_AP_CHANNEL)) { + int channel; + sscanf(EXAMPLE_ESP_WIFI_AP_CHANNEL, "%d", &channel); + wifi_config.ap.channel = channel; + } if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) { wifi_config.ap.authmode = WIFI_AUTH_OPEN; } diff --git a/examples/single_chip/recognition_wechat/main/Kconfig.projbuild b/examples/single_chip/recognition_wechat/main/Kconfig.projbuild index eae51b5..8acf12f 100644 --- a/examples/single_chip/recognition_wechat/main/Kconfig.projbuild +++ b/examples/single_chip/recognition_wechat/main/Kconfig.projbuild @@ -18,6 +18,12 @@ config MAX_STA_CONN help Max number of the STA connects to AP. +config ESP_WIFI_AP_CHANNEL + string "WiFi AP Channel" + default "" + help + AP channel for better connection performance. + config SERVER_IP string "IP address of server" default "192.168.4.1" diff --git a/examples/single_chip/recognition_wechat/main/app_wifi.c b/examples/single_chip/recognition_wechat/main/app_wifi.c index 9e56a68..a9893e4 100644 --- a/examples/single_chip/recognition_wechat/main/app_wifi.c +++ b/examples/single_chip/recognition_wechat/main/app_wifi.c @@ -41,6 +41,7 @@ static const char *TAG = "app_wifi"; #define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD #define EXAMPLE_MAX_STA_CONN CONFIG_MAX_STA_CONN #define EXAMPLE_IP_ADDR CONFIG_SERVER_IP +#define EXAMPLE_ESP_WIFI_AP_CHANNEL CONFIG_ESP_WIFI_AP_CHANNEL static esp_err_t event_handler(void *ctx, system_event_t *event) {/*{{{*/ @@ -115,6 +116,11 @@ static void wifi_init_softap() if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) { wifi_config.ap.authmode = WIFI_AUTH_OPEN; } + if (strlen(EXAMPLE_ESP_WIFI_AP_CHANNEL)) { + int channel; + sscanf(EXAMPLE_ESP_WIFI_AP_CHANNEL, "%d", &channel); + wifi_config.ap.channel = channel; + } esp_wifi_set_ps(WIFI_PS_NONE); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));