C# – Getting Wireless Network Strength

ccompact-frameworkopennetcfwindows-mobile-5.0wireless

I'm having difficulty getting the wireless signal strength in a C#, Compact Framework 3.5, Windows Mobile 5 project using OpenNetCF version 2.3. I am aiming to assess the strength of network access before sending requests as the network coverage for this device will likely be patchy.

After googleing around I found two possible leads. An example project from Microsoft that uses the now AccessPoint class which is marked as deprecated in the OpenNETCF 2.3 and some suggestions saying to use the SignalStrength property on the WirelessNetworkingInterface class. This seems like a good Idea in theory however the factory method which appears as though it should return this class OpenNETCF.Net.NetworkInformation.WirelessNetworkInterface.GetAllNetworkInterfaces() instead returns INetworkInterface class which does not expose the SignalStrength property.

Has anyone managed to assess wireless strength using OpenNETCF 2.3?
Am I not understanding the correct usage of this package? Or has anyone developed a work around for this problem?

Any guidance or help would be very useful.

Best Answer

GetAllNetworkInterfaces() returns an array of INetworkInterface interfaces because you might (and very often do) have different concrete types on the same device. The question is what is the instance type you got back for your wireless NIC? It will be a NetworkInterface, a WirelessNetworkInterface or a WirelessZeroConfigNetowrkInterface. You can cast the interface version to the concrete type and then get the signal strength provided it's of a type that exposes that information.

foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
{
    var wzc = ni as WirelessZeroConfigNetworkInterface;
    if(wzc != null)
    {
        Debug.Writeline("WZC Signal: " + wzc.SignalStrength.Decibels);
        continue;
    }

    var wni = ni as WirelessNetworkInterface 
    if(wni != null)
    {
        Debug.Writeline("Wireless Signal: " + wni.SignalStrength.Decibels);
        continue;
    }

    Debug.Writeline("No signal info available");
}               
Related Topic