ifconfig.rs
1 use crate::services::system; 2 use alloc::string::String as AllocString; 3 use core::fmt::Write; 4 use esp_hal::efuse; 5 6 pub fn run() -> AllocString { 7 let mut out = AllocString::new(); 8 let info = system::snapshot(); 9 let mac = efuse::base_mac_address(); 10 11 let _ = write!(out, "\r\n"); 12 let _ = write!( 13 out, 14 " \x1b[33m{:<12}\x1b[0m {}\r\n", 15 "STA", 16 if info.network.station.is_connected { 17 "\x1b[32mconnected\x1b[0m" 18 } else { 19 "\x1b[31mdisconnected\x1b[0m" 20 } 21 ); 22 let _ = write!( 23 out, 24 " \x1b[33m{:<12}\x1b[0m {}.{}.{}.{}/24\r\n", 25 "IPv4", 26 info.network.station.ipv4_address[0], 27 info.network.station.ipv4_address[1], 28 info.network.station.ipv4_address[2], 29 info.network.station.ipv4_address[3] 30 ); 31 let _ = write!( 32 out, 33 " \x1b[33m{:<12}\x1b[0m {:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}\r\n", 34 "MAC", 35 mac.as_bytes()[0], 36 mac.as_bytes()[1], 37 mac.as_bytes()[2], 38 mac.as_bytes()[3], 39 mac.as_bytes()[4], 40 mac.as_bytes()[5] 41 ); 42 let _ = write!( 43 out, 44 " \x1b[33m{:<12}\x1b[0m {} (ch {}, {}, fallback={})\r\n", 45 "AP", 46 info.network.access_point.ssid, 47 info.network.access_point.channel, 48 info.network.access_point.auth_mode, 49 if info.network.access_point.fallback_enabled { 50 "yes" 51 } else { 52 "no" 53 } 54 ); 55 let _ = write!(out, "\r\n"); 56 57 out 58 }