rework wifi controller share
This commit is contained in:
@@ -21,8 +21,8 @@ use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
struct SSIDList<'a> {
|
||||
ssids: Vec<&'a String>,
|
||||
struct SSIDList {
|
||||
ssids: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
@@ -369,6 +369,7 @@ impl Handler for HttpHandler {
|
||||
"/files" => Some(list_files(conn).await),
|
||||
"/log_localization" => Some(get_log_localization_config(conn).await),
|
||||
"/log" => Some(get_log(conn).await),
|
||||
"/wifiscan" => Some(wifi_scan(conn).await),
|
||||
_ => None,
|
||||
};
|
||||
match json {
|
||||
@@ -377,7 +378,17 @@ impl Handler for HttpHandler {
|
||||
}
|
||||
}
|
||||
},
|
||||
Method::Options | Method::Delete | Method::Head | Method::Post | Method::Put => None,
|
||||
Method::Post => {
|
||||
let json = match path {
|
||||
"/wifiscan" => Some(wifi_scan(conn).await),
|
||||
_ => None,
|
||||
};
|
||||
match json {
|
||||
None => None,
|
||||
Some(json) => Some(handle_json(conn, json).await?),
|
||||
}
|
||||
}
|
||||
Method::Options | Method::Delete | Method::Head | Method::Put => None,
|
||||
_ => None,
|
||||
};
|
||||
let code = match status {
|
||||
@@ -406,6 +417,33 @@ impl Handler for HttpHandler {
|
||||
// reboot_now_for_reboot.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
// anyhow::Ok(())
|
||||
|
||||
// fn wifi_scan(
|
||||
// _request: &mut Request<&mut EspHttpConnection>,
|
||||
// ) -> Result<Option<std::string::String>, anyhow::Error> {
|
||||
// let mut board = BOARD_ACCESS.lock().unwrap();
|
||||
// let scan_result = board.board_hal.get_esp().wifi_scan()?;
|
||||
// let mut ssids: Vec<&String<32>> = Vec::new();
|
||||
// scan_result.iter().for_each(|s| ssids.push(&s.ssid));
|
||||
// let ssid_json = serde_json::to_string(&SSIDList { ssids })?;
|
||||
// log::info!("Sending ssid list {}", &ssid_json);
|
||||
// anyhow::Ok(Some(ssid_json))
|
||||
// }
|
||||
|
||||
async fn wifi_scan<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> Result<Option<String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
info!("start wifi scan");
|
||||
let scan_result = board.board_hal.get_esp().wifi_scan().await;
|
||||
let mut ssids: Vec<String> = Vec::new();
|
||||
scan_result
|
||||
.iter()
|
||||
.for_each(|s| ssids.push(s.ssid.to_string()));
|
||||
let ssid_json = serde_json::to_string(&SSIDList { ssids })?;
|
||||
info!("Sending ssid list {}", &ssid_json);
|
||||
anyhow::Ok(Some(ssid_json))
|
||||
}
|
||||
|
||||
async fn get_log<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> Result<Option<String>, anyhow::Error> {
|
||||
|
||||
Reference in New Issue
Block a user