3
votes

I am currently running with a portable device running Ubuntu 15.10. The idea is that this unit will have no screen (a secondary device will be optionally connected to it, but standalone, it's for data recording out in the field), and read from a list of SSIDs and Wifi-Passwords to connect to them when available.

We are currently using Mono C# on the device, but hitting a snag when it comes to wifi.

My question is this: Is there a class or DLL I need to implement inside of the C# environment to get the Access Points, and connect using a password, or alternatively, a terminal tool that will A) return a list of APs available and B) can take in an SSID and Password and attempt a connection?

Thank you for your help.

Current Solution: I run a process of nmcli, attempting to parse the incoming stream (not good at this on Linux yet), to get a list of SSIDs.

After some comparison, I run another process, calling "nmcli dev wifi connect password " based on a text file.

This is currently working, but I'm wondering if there are better solutions.

Edit 2: The major issue with the above is that, if a bad password is provided, it launches the Password Required window and locks up the system.

Edit 3: After messing around with the nm-applet, killing it to stop the pop up, a series of 802.1X errors appeared, though not every time. If I attempt the connection enough times, it succeeds eventually.

Edit 4: Re-installing network-manager seems to have fixed a few problems, but still buggy.

Edit 5: In regards to iwConfig, I tried that, but I found that when I used iwlist wlan0 scan | grep ESSID, it only returned the current connected network 9/10 times.

1
@RQDQ thats basically the question about how to connect to wifi in Ubuntu via command line, not? There is not much reason to use pinvoke or something to do that, just call command line tools.Evk
@Evk - no, the question is specifically about doing this from c#/mono. The OP shared that he's using the command line, but it's not working well.RQDQ
I understand, but that most likely just means he uses wrong tools (or in a wrong way). Asking because trying to understand if you really need pinvoke solution or command line tools will still do.Evk

1 Answers

1
votes

You basically want to implement a C# API for NetworkManager's D-Bus API.

To scan the available wireless networks, you should connect to NetworkManager's D-Bus, call the getDevices method, and call its getNetworks.

See dbus-sharp for a D-Bus API for mono/C#. Read more about NetworkManager's D-Bus API in here. See here an example for an implementation of an interaction between dbus-sharp and NetworkManager.

Keep in mind that this will only work on Linux systems that use NetworkManager (Almost all major Linux distributions, including Ubuntu).