|
| 1 | +//! Wi-Fi info example |
| 2 | +//! |
| 3 | +//! This example prints out all the info about the console's network, like SSID, security, proxy info... |
| 4 | +
|
| 5 | +use ctru::{ |
| 6 | + prelude::*, |
| 7 | + services::ac::{Ac, NetworkStatus}, |
| 8 | +}; |
| 9 | +use std::error::Error; |
| 10 | + |
| 11 | +fn main() { |
| 12 | + let gfx = Gfx::new().expect("Couldn't obtain GFX controller"); |
| 13 | + let mut hid = Hid::new().expect("Couldn't obtain HID controller"); |
| 14 | + let apt = Apt::new().expect("Couldn't obtain APT controller"); |
| 15 | + |
| 16 | + ctru::set_panic_hook(true); |
| 17 | + |
| 18 | + let _console = Console::new(gfx.top_screen.borrow_mut()); |
| 19 | + |
| 20 | + let ac = Ac::new().expect("Couldn't get an AC handle"); |
| 21 | + |
| 22 | + print_network_info(&ac).expect("Error while gathering network info"); |
| 23 | + println!("Press START to exit."); |
| 24 | + |
| 25 | + while apt.main_loop() { |
| 26 | + hid.scan_input(); |
| 27 | + |
| 28 | + if hid.keys_down().contains(KeyPad::START) { |
| 29 | + break; |
| 30 | + } |
| 31 | + |
| 32 | + gfx.wait_for_vblank(); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +fn print_network_info(ac: &Ac) -> Result<(), Box<dyn Error>> { |
| 37 | + let status = ac.wifi_status()?; |
| 38 | + println!("Wi-Fi status: {:?}", status); |
| 39 | + |
| 40 | + // Some methods error out if the console isn't connected |
| 41 | + if matches!( |
| 42 | + status, |
| 43 | + NetworkStatus::WANConnected | NetworkStatus::LANConnected |
| 44 | + ) { |
| 45 | + println!("Wi-Fi SSID: {}", String::from_utf8(ac.wifi_ssid()?)?); |
| 46 | + println!("Wi-Fi security: {:?}", ac.wifi_security()?); |
| 47 | + let proxied = ac.proxy_enabled()?; |
| 48 | + println!("Proxy enabled: {}", proxied); |
| 49 | + if proxied { |
| 50 | + println!("Proxy port: {}", ac.proxy_port()?); |
| 51 | + println!( |
| 52 | + "Proxy username: {}", |
| 53 | + String::from_utf8(ac.proxy_username()?)? |
| 54 | + ); |
| 55 | + println!( |
| 56 | + "Proxy password: {}", |
| 57 | + String::from_utf8(ac.proxy_password()?)? |
| 58 | + ); |
| 59 | + } |
| 60 | + } else { |
| 61 | + println!("Not connected to any network.") |
| 62 | + } |
| 63 | + |
| 64 | + Ok(()) |
| 65 | +} |
0 commit comments