8000 Option to choose WIFI_MODE_APSTA when connecting to an AP by damonsmith · Pull Request #582 · nkolban/esp32-snippets · GitHub
[go: up one dir, main page]

Skip to content

Option to choose WIFI_MODE_APSTA when connecting to an AP #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cpp_utils/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ void WiFi::setDNSServer(int numdns, ip_addr_t ip) {
* @param [in] ssid The network SSID of the access point to which we wish to connect.
* @param [in] password The password of the access point to which we wish to connect.
* @param [in] waitForConnection Block until the connection has an outcome.
* @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.
* @param [in] mode WIFI_MODE_AP for normal or WIFI_MODE_APSTA if you want to keep an Access Point running while you connect
* @return ESP_OK if we are now connected and wifi_err_reason_t if not.
*/
uint8_t WiFi::connectAP(const std::string& ssid, const std::string& password, bool waitForConnection){
uint8_t WiFi::connectAP(const std::string& ssid, const std::string& password, bool waitForConnection, wifi_mode_t mode){
ESP_LOGD(LOG_TAG, ">> connectAP");

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

esp_err_t errRc = ::esp_wifi_set_mode(WIFI_MODE_STA);
esp_err_t errRc = ::esp_wifi_set_mode(mode);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_wifi_set_mode: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
abort();
Expand Down
2 changes: 1 addition & 1 deletion cpp_utils/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class WiFi {
void setDNSServer(int numdns, ip_addr_t ip);
struct in_addr getHostByName(const std::string& hostName);
struct in_addr getHostByName(const char* hostName);
uint8_t connectAP(const std::string& ssid, const std::string& password, bool waitForConnection=true);
uint8_t connectAP(const std::string& ssid, const std::string& password, bool waitForConnection=true, wifi_mode_t mode=WIFI_MODE_STA);
void dump();
bool isConnectedToAP();
static std::string getApMac();
Expand Down
0