10000 Merge pull request #582 from damonsmith/master · AlexanderKa1/esp32-snippets@faf2839 · GitHub
[go: up one dir, main page]

Skip to content

Commit faf2839

Browse files
authored
Merge pull request nkolban#582 from damonsmith/master
Option to choose WIFI_MODE_APSTA when connecting to an AP
2 parents 4743dfc + cc56443 commit faf2839

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cpp_utils/WiFi.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ void WiFi::setDNSServer(int numdns, ip_addr_t ip) {
153153
* @param [in] ssid The network SSID of the access point to which we wish to connect.
154154
* @param [in] password The password of the access point to which we wish to connect.
155155
* @param [in] waitForConnection Block until the connection has an outcome.
156-
* @returns ESP_OK if successfully receives a SYSTEM_EVENT_STA_GOT_IP event. Otherwise returns wifi_err_reason_t - use GeneralUtils::wifiErrorToString(uint8_t errCode) to print the error.
156+
* @param [in] mode WIFI_MODE_AP for normal or WIFI_MODE_APSTA if you want to keep an Access Point running while you connect
157+
* @return ESP_OK if we are now connected and wifi_err_reason_t if not.
157158
*/
158-
uint8_t WiFi::connectAP(const std::string& ssid, const std::string& password, bool waitForConnection){
159+
uint8_t WiFi::connectAP(const std::string& ssid, const std::string& password, bool waitForConnection, wifi_mode_t mode){
159160
ESP_LOGD(LOG_TAG, ">> connectAP");
160161

161162
m_apConnectionStatus = UINT8_MAX;
@@ -172,7 +173,7 @@ uint8_t WiFi::connectAP(const std::string& ssid, const std::string& password, bo
172173
::tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ipInfo);
173174
}
174175

175-
esp_err_t errRc = ::esp_wifi_set_mode(WIFI_MODE_STA);
176+
esp_err_t errRc = ::esp_wifi_set_mode(mode);
176177
if (errRc != ESP_OK) {
177178
ESP_LOGE(LOG_TAG, "esp_wifi_set_mode: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
178179
abort();

cpp_utils/WiFi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class WiFi {
130130
void setDNSServer(int numdns, ip_addr_t ip);
131131
struct in_addr getHostByName(const std::string& hostName);
132132
struct in_addr getHostByName(const char* hostName);
133-
uint8_t connectAP(const std::string& ssid, const std::string& password, bool waitForConnection=true);
133+
uint8_t connectAP(const std::string& ssid, const std::string& password, bool waitForConnection=true, wifi_mode_t mode=WIFI_MODE_STA);
134134
void dump();
135135
bool isConnectedToAP();
136136
static std::string getApMac();

0 commit comments

Comments
 (0)
0