Skip to content

Conversation

sundaram123krishnan
Copy link

Implementing wifi speed using nmcli for linux

@sundaram123krishnan
Copy link
Author

Feel free to suggest any modifications.

fn disconnect(&self) -> Result<bool, WifiConnectionError>;

// determines speed when connected to a network
fn speed(&self) -> Result<String, WifiConnectionError>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide a default implementation of unimplemented!(). This should prevent the build from failing for other targets.

/// Disconnects from a wireless network currently connected to.
fn disconnect(&self) -> Result<bool, WifiConnectionError>;

// determines speed when connected to a network
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Start with caps.

Comment on lines +65 to +70
let piped_awk = Command::new("awk")
.arg(r"/\*/{if (NR!=1) {print $6}}")
.stdin(Stdio::from(nmcli_speed.stdout.unwrap())) // Pipe through.
.stdout(Stdio::piped())
.spawn()
.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be parsed manually. We'll want to reduce as much dependency as possible on external programs.

In the future, I plan to remove dependency on nmcli for a similar reason.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when parsing manually, could you add test cases to verify we're parsing the output of nmcli correctly?

.arg("list")
.stdout(Stdio::piped())
.spawn()
.expect("nothing");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle this error correctly i.e. use the WifiConnectionError type.

Comment on lines 9 to 21
use std::process::{Command, Stdio};

fn main() -> Result<(), WifiConnectionError> {
let config = Some(Config {
interface: Some("wlo1"),
interface: Some("wlan0"),
});

let mut wifi = WiFi::new(config);

match wifi.connect("CSIS_MH", "") {
match wifi.connect("TP-Link_CEE2", "05Bs@sdfvn") {
Ok(result) => println!(
"{}",
if result == true {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure these changes are needed. You can easily setup a test program that points to your own version of the changes.

@toksdotdev
Copy link
Owner

Thanks for the improvement. 😃 Could you kindly address the above changes?

@sundaram123krishnan
Copy link
Author

Thx for the suggestions, will definitely make improvements

@sundaram123krishnan
Copy link
Author

reflected on changes that you mentioned

@sundaram123krishnan
Copy link
Author

yaa will definitely try to implement features without external libraries like nmcli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants