wifi: implement station change and connect
This commit is contained in:
@@ -55,18 +55,18 @@ impl WifiStore {
|
||||
match nvs_lock.get::<bool>(&NVS_NAMESPACE_WIFI, &NVS_WIFI_INITIALIZED_KEY) {
|
||||
Ok(initialized) => {
|
||||
log::debug!("initialization_check: initialized {initialized:?}");
|
||||
return Ok(true);
|
||||
Ok(true)
|
||||
}
|
||||
Err(esp_nvs::error::Error::NamespaceNotFound) => {
|
||||
log::debug!("initialization_check: error: namespace not found");
|
||||
return Ok(false);
|
||||
Ok(false)
|
||||
}
|
||||
Err(esp_nvs::error::Error::KeyNotFound) => {
|
||||
log::debug!("initialization_check: error: key not found");
|
||||
return Ok(false);
|
||||
Ok(false)
|
||||
}
|
||||
Err(error) => return Err(error.into()),
|
||||
};
|
||||
Err(error) => Err(error.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn initialize(nvs: &Mutex<Nvs>) -> Result<(), WifiStoreError> {
|
||||
@@ -74,14 +74,14 @@ impl WifiStore {
|
||||
|
||||
let mut nvs_lock = nvs.lock().await;
|
||||
|
||||
log::debug!("initialization: write dummy ssid");
|
||||
log::debug!("initialization: write empty ssid");
|
||||
nvs_lock.set::<&str>(
|
||||
&NVS_NAMESPACE_WIFI,
|
||||
&NVS_WIFI_SSID_KEY,
|
||||
""
|
||||
)?;
|
||||
|
||||
log::debug!("initialization: write dummy pass");
|
||||
log::debug!("initialization: write empty pass");
|
||||
nvs_lock.set::<&str>(
|
||||
&NVS_NAMESPACE_WIFI,
|
||||
&NVS_WIFI_PASS_KEY,
|
||||
@@ -99,18 +99,22 @@ impl WifiStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn load_credentials(&self) -> Result<WifiCredentials, WifiStoreError> {
|
||||
pub async fn load_credentials(&self) -> Result<Option<WifiCredentials>, WifiStoreError> {
|
||||
log::debug!("loading wifi credentials");
|
||||
log::debug!("loading ssid");
|
||||
let mut nvs_lock = self.nvs.lock().await;
|
||||
let ssid = nvs_lock.get::<String>(&NVS_NAMESPACE_WIFI, &NVS_WIFI_SSID_KEY)?;
|
||||
if ssid.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
log::debug!("ssid: {ssid}");
|
||||
|
||||
log::debug!("loading pass");
|
||||
let pass = nvs_lock.get::<String>(&NVS_NAMESPACE_WIFI, &NVS_WIFI_PASS_KEY)?;
|
||||
|
||||
log::debug!("pass: {pass}");
|
||||
|
||||
Ok(WifiCredentials{ssid, pass})
|
||||
Ok(Some(WifiCredentials{ssid, pass}))
|
||||
}
|
||||
|
||||
pub async fn save_credentials(&self, credentials: &WifiCredentials) -> Result<(), WifiStoreError> {
|
||||
|
||||
Reference in New Issue
Block a user