Some RP2040 wifi changes for AP mode (#3953)

This commit is contained in:
Jesse Hills 2022-10-27 19:14:41 +13:00 committed by GitHub
parent 85faecb2fd
commit a5d4ca0f6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,11 @@ bool WiFiComponent::wifi_mode_(optional<bool> sta, optional<bool> ap) {
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_STA, true, CYW43_COUNTRY_WORLDWIDE);
}
}
if (ap.has_value()) {
if (ap.value()) {
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_AP, true, CYW43_COUNTRY_WORLDWIDE);
}
}
return true;
}
@ -141,22 +146,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
if (!this->wifi_mode_({}, true))
return false;
if (ap.get_channel().has_value()) {
cyw43_wifi_ap_set_channel(&cyw43_state, ap.get_channel().value());
}
const char *ssid = ap.get_ssid().c_str();
cyw43_wifi_ap_set_ssid(&cyw43_state, strlen(ssid), (const uint8_t *) ssid);
if (!ap.get_password().empty()) {
const char *password = ap.get_password().c_str();
cyw43_wifi_ap_set_password(&cyw43_state, strlen(password), (const uint8_t *) password);
cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_WPA2_MIXED_PSK);
} else {
cyw43_wifi_ap_set_auth(&cyw43_state, CYW43_AUTH_OPEN);
}
cyw43_wifi_set_up(&cyw43_state, CYW43_ITF_AP, true, CYW43_COUNTRY_WORLDWIDE);
WiFi.beginAP(ap.get_ssid().c_str(), ap.get_password().c_str(), ap.get_channel().value_or(1));
return true;
}