wifi.rs
1 use crate::api::{WifiScanResponse, WifiNetwork, WirelessStatusResponse}; 2 use reqwest::Error; 3 4 pub struct WifiService; 5 6 impl WifiService { 7 pub async fn get_status(base_url: &str) -> Result<WirelessStatusResponse, Error> { 8 reqwest::get(format!("{base_url}/api/wireless/status")) 9 .await? 10 .json() 11 .await 12 } 13 14 pub async fn scan(base_url: &str) -> Result<WifiScanResponse, Error> { 15 reqwest::Client::new() 16 .post(format!("{base_url}/api/wireless/actions/scan")) 17 .send() 18 .await? 19 .json() 20 .await 21 } 22 23 pub async fn connect(base_url: &str, ssid: &str, password: &str) -> Result<serde_json::Value, Error> { 24 reqwest::Client::new() 25 .post(format!("{base_url}/api/wireless/actions/connect")) 26 .json(&serde_json::json!({ "ssid": ssid, "password": password })) 27 .send() 28 .await? 29 .json() 30 .await 31 } 32 }