Skip to content
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

Added non-blocking connect method #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ int WiFiClass::begin(const char* ssid)
return status;
}

int WiFiClass::connect(const char* ssid) {
uint8_t status = WL_CONNECT_FAILED;
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE) {
status = WiFiDrv::getConnectionStatus();
}
return status;
}

int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
{
uint8_t status = WL_IDLE_STATUS;
Expand All @@ -80,6 +88,15 @@ int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
return status;
}

int WiFiClass::connect(const char* ssid, uint8_t key_idx, const char *key) {
uint8_t status = WL_CONNECT_FAILED;
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE) {
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
}
return status;
}

int WiFiClass::begin(const char* ssid, const char *passphrase)
{
uint8_t status = WL_IDLE_STATUS;
Expand All @@ -100,6 +117,15 @@ int WiFiClass::begin(const char* ssid, const char *passphrase)
return status;
}

int WiFiClass::connect(const char* ssid, const char *passphrase) {
uint8_t status = WL_CONNECT_FAILED;
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE) {
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
}
return status;
}

uint8_t WiFiClass::beginAP(const char *ssid)
{
return beginAP(ssid, 1);
Expand Down
4 changes: 4 additions & 0 deletions src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class WiFiClass
*/
int begin(const char* ssid, const char *passphrase);

int connect(const char* ssid);
int connect(const char* ssid, uint8_t key_idx, const char* key);
int connect(const char* ssid, const char *passphrase);

uint8_t beginAP(const char *ssid);
uint8_t beginAP(const char *ssid, uint8_t channel);
uint8_t beginAP(const char *ssid, const char* passphrase);
Expand Down