Introduction
ManagedWiFi is a library to control WiFi on Windows. It wraps NDISUIO driver and allow you to get information from your 802.11b or 802.11g NIC. You can manage WiFi from C#, VB.NET and all the languages targeting the .NET CLR.
Notes
The library relies on NDISUIO, which is an interface in user mode based on a named pipe that allows communication with NDIS drivers. Unfortunately the named pipe is bound by the Windows Wireless Zero Configuration Service, so if you try to run the code you'll get an in opening the Pipe. You should stop this service (in the Services tool in the Administrative Tools section) before starting an application that make use of this library.
Beware: the information supplied by the library depends on the implementation of NDIS interface of the various drivers. For instance we have a NIC whose driver returns the signal strength only for the bound network.
Why in Robotics4.NET?
WiFi is an interesting perception for a robot. It is a perception that depends on the particular position of the robot. We use it to help locate our robot in the building.
Example
The following example shows how easy and cool is our library! Here we check the signal strength of all WiFi networks available, and we bound to the strongest AP we've found.
Show
static void Main(string[] args) {
WirelessManager.Init();
// Bind the Wireless device to be used
foreach (NdisDevice d in WirelessManager.EnumerateDevices()) {
// FIXME: At the moment we can't decide the type of NIC (either 802.3 or 802.11)
// We assume that the description of the card helps us
if (d.Description.IndexOf("Wireless") != -1 || d.Description.IndexOf("WLAN") != -1) {
WirelessManager.CurrentDevice = d;
break;
}
}
// We try to bind the best AP
int signal = -300; // Signal is in decibel (from -20 to -200)
string ssid = null;
// Enumerate Access Points
foreach (AccessPoint ap in WirelessManager.CurrentDevice.ScanAPList()) {
if (ap.InfrastructureMode == NDIS_802_11_NETWORK_INFRASTRUCTURE.Ndis802_11Infrastructure &&
ap.SignalStrength > signal) {
signal = ap.SignalStrength;
ssid = ap.SSID;
}
Console.WriteLine("AP {0}", ap.MAC);
Console.WriteLine("SSID: {0}", ap.SSID);
Console.WriteLine("Signal strength: {0}", ap.SignalStrength);
Console.WriteLine("Infrastructure mode: {0}",
(ap.InfrastructureMode == NDIS_802_11_NETWORK_INFRASTRUCTURE.Ndis802_11Infrastructure ?
"Access Point" : "Ad Hoc"));
Console.WriteLine();
}
// Try to bind the best AP
if (ssid != null && ssid != "") {
Console.WriteLine("Attempting to bind {0}", ssid);
WirelessManager.SSID = ssid;
}
}