1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 15:12:06 +00:00
This commit is contained in:
J. Nick Koston
2025-10-04 22:02:32 -05:00
parent 6cf6fcf4e6
commit 4687e58b03

View File

@@ -316,9 +316,9 @@ void WiFiComponent::set_sta(const WiFiAP &ap) {
} }
void WiFiComponent::clear_sta() { this->sta_.clear(); } void WiFiComponent::clear_sta() { this->sta_.clear(); }
void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &password) { void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &password) {
SavedWifiSettings save{}; // zero-initialized SavedWifiSettings save{}; // zero-initialized - all bytes set to \0, guaranteeing null termination
strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid) - 1); strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid) - 1); // max 32 chars, byte 32 remains \0
strncpy(save.password, password.c_str(), sizeof(save.password) - 1); strncpy(save.password, password.c_str(), sizeof(save.password) - 1); // max 64 chars, byte 64 remains \0
this->pref_.save(&save); this->pref_.save(&save);
// ensure it's written immediately // ensure it's written immediately
global_preferences->sync(); global_preferences->sync();