Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions ctru-rs/examples/wifi-info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Wi-Fi info example
//!
//! This example prints out all the info about the console's network, like SSID, security, proxy info...

use ctru::{
prelude::*,
services::ac::{Ac, NetworkStatus},
};
use std::error::Error;

fn main() {
let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");

ctru::set_panic_hook(true);

let _console = Console::new(gfx.top_screen.borrow_mut());

let ac = Ac::new().expect("Couldn't get an AC handle");

print_network_info(&ac).expect("Error while gathering network info");
println!("Press START to exit.");

while apt.main_loop() {
hid.scan_input();

if hid.keys_down().contains(KeyPad::START) {
break;
}

gfx.wait_for_vblank();
}
}

fn print_network_info(ac: &Ac) -> Result<(), Box<dyn Error>> {
let status = ac.wifi_status()?;
println!("Wi-Fi status: {:?}", status);

Check warning on line 38 in ctru-rs/examples/wifi-info.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2025-07-25)

variables can be used directly in the `format!` string

// Some methods error out if the console isn't connected
if matches!(
status,
NetworkStatus::WANConnected | NetworkStatus::LANConnected
) {
println!("Wi-Fi SSID: {}", String::from_utf8(ac.wifi_ssid()?)?);
println!("Wi-Fi security: {:?}", ac.wifi_security()?);
let proxied = ac.proxy_enabled()?;
println!("Proxy enabled: {}", proxied);

Check warning on line 48 in ctru-rs/examples/wifi-info.rs

View workflow job for this annotation

GitHub Actions / lint (nightly-2025-07-25)

variables can be used directly in the `format!` string
if proxied {
println!("Proxy port: {}", ac.proxy_port()?);
println!(
"Proxy username: {}",
String::from_utf8(ac.proxy_username()?)?
);
println!(
"Proxy password: {}",
String::from_utf8(ac.proxy_password()?)?
);
}
} else {
println!("Not connected to any network.")
}

Ok(())
}
Loading
Loading