Bssid (#1212)
* Add BSSID connection options to PicoW When working with a mesh or multiple APs with the same SSID, it is often necessary to specify which of the APs to connect to in order to maximize the WiFi strength. Add BSSID options to the SDK's PicoW cyw43_arch_wifi_connect_XXX APIs. Fixes #1090 Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
This commit is contained in:
@ -69,15 +69,19 @@ const char* cyw43_tcpip_link_status_name(int status)
|
||||
}
|
||||
#endif
|
||||
|
||||
int cyw43_arch_wifi_connect_async(const char *ssid, const char *pw, uint32_t auth) {
|
||||
|
||||
int cyw43_arch_wifi_connect_bssid_async(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth) {
|
||||
if (!pw) auth = CYW43_AUTH_OPEN;
|
||||
// Connect to wireless
|
||||
return cyw43_wifi_join(&cyw43_state, strlen(ssid), (const uint8_t *)ssid, pw ? strlen(pw) : 0, (const uint8_t *)pw, auth, NULL, CYW43_ITF_STA);
|
||||
return cyw43_wifi_join(&cyw43_state, strlen(ssid), (const uint8_t *)ssid, pw ? strlen(pw) : 0, (const uint8_t *)pw, auth, bssid, CYW43_CHANNEL_NONE);
|
||||
}
|
||||
|
||||
// Connect to wireless, return with success when an IP address has been assigned
|
||||
static int cyw43_arch_wifi_connect_until(const char *ssid, const char *pw, uint32_t auth, absolute_time_t until) {
|
||||
int err = cyw43_arch_wifi_connect_async(ssid, pw, auth);
|
||||
int cyw43_arch_wifi_connect_async(const char *ssid, const char *pw, uint32_t auth) {
|
||||
return cyw43_arch_wifi_connect_bssid_async(ssid, NULL, pw, auth);
|
||||
}
|
||||
|
||||
static int cyw43_arch_wifi_connect_bssid_until(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth, absolute_time_t until) {
|
||||
int err = cyw43_arch_wifi_connect_bssid_async(ssid, bssid, pw, auth);
|
||||
if (err) return err;
|
||||
|
||||
int status = CYW43_LINK_UP + 1;
|
||||
@ -86,7 +90,7 @@ static int cyw43_arch_wifi_connect_until(const char *ssid, const char *pw, uint3
|
||||
// If there was no network, keep trying
|
||||
if (new_status == CYW43_LINK_NONET) {
|
||||
new_status = CYW43_LINK_JOIN;
|
||||
err = cyw43_arch_wifi_connect_async(ssid, pw, auth);
|
||||
err = cyw43_arch_wifi_connect_bssid_async(ssid, bssid, pw, auth);
|
||||
if (err) return err;
|
||||
}
|
||||
if (new_status != status) {
|
||||
@ -111,14 +115,27 @@ static int cyw43_arch_wifi_connect_until(const char *ssid, const char *pw, uint3
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to wireless, return with success when an IP address has been assigned
|
||||
static int cyw43_arch_wifi_connect_until(const char *ssid, const char *pw, uint32_t auth, absolute_time_t until) {
|
||||
return cyw43_arch_wifi_connect_bssid_until(ssid, NULL, pw, auth, until);
|
||||
}
|
||||
|
||||
int cyw43_arch_wifi_connect_blocking(const char *ssid, const char *pw, uint32_t auth) {
|
||||
return cyw43_arch_wifi_connect_until(ssid, pw, auth, at_the_end_of_time);
|
||||
}
|
||||
|
||||
int cyw43_arch_wifi_connect_bssid_blocking(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth) {
|
||||
return cyw43_arch_wifi_connect_bssid_until(ssid, bssid, pw, auth, at_the_end_of_time);
|
||||
}
|
||||
|
||||
int cyw43_arch_wifi_connect_timeout_ms(const char *ssid, const char *pw, uint32_t auth, uint32_t timeout_ms) {
|
||||
return cyw43_arch_wifi_connect_until(ssid, pw, auth, make_timeout_time_ms(timeout_ms));
|
||||
}
|
||||
|
||||
int cyw43_arch_wifi_connect_bssid_timeout_ms(const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth, uint32_t timeout_ms) {
|
||||
return cyw43_arch_wifi_connect_bssid_until(ssid, bssid, pw, auth, make_timeout_time_ms(timeout_ms));
|
||||
}
|
||||
|
||||
uint32_t cyw43_arch_get_country_code(void) {
|
||||
return country_code;
|
||||
}
|
||||
@ -151,4 +168,4 @@ void cyw43_arch_poll(void)
|
||||
|
||||
void cyw43_arch_wait_for_work_until(absolute_time_t until) {
|
||||
async_context_wait_for_work_until(async_context, until);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user