Display visible WiFi networks

This commit is contained in:
2024-12-26 11:49:09 +01:00
parent e03dbe7165
commit 249b33c74e
2 changed files with 45 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ use improv_setup::improv::{
ImprovPacket,
RequestCurrentStatePacket,
RequestDeviceInformationPacket,
RequestScannedWiFiNetworksPacket,
};
use improv_setup::serial;
use tokio_serial;
@@ -30,6 +31,8 @@ enum DeviceCommands {
},
/// Request device info
Info,
/// WiFi networks visible to device
Scan,
}
impl Default for DeviceCommands {
@@ -118,6 +121,29 @@ async fn main() -> Result<()>{
}
}
},
DeviceCommands::Scan => {
let request_scanned_wifi_networks_packet = RequestScannedWiFiNetworksPacket {};
let mut serial_interface = serial::SerialInterface::new(path, *baud_rate).context("Couldn't init serial interface")?;
serial_interface.send(&request_scanned_wifi_networks_packet).context("Failed to send improv packet")?;
loop {
let result_bytes = serial_interface.recv_bytes().context("Couldn't receive any improv packet")?;
let raw_packet = RawPacket::try_from_bytes(&result_bytes).context("Failed to deserialize packet")?;
if let ImprovPacket::RPCResult(rpc_result) = ImprovPacket::try_from_raw_packet(&raw_packet).context("Failed to read packet")? {
if rpc_result.results.len() <= 0 {
break;
}
println!("{:<25} {:>3} {}", &rpc_result.results[0], &rpc_result.results[1], match rpc_result.results[2].as_str() {
"YES" => "secure",
"NO" => "open",
_ => "",
});
}
}
},
};
},