locked
Get signal strength in C#?

    Question

  • Is there a way to retreive the wireless signal strength?

    Thanks,

    Sunday, September 10, 2006 3:42 PM

Answers

  • try this:

    private double RetrieveSignalString()

    {

       double theSignalStrength = 0;

       ConnectionOptions theConnectionOptions = new ConnectionOptions();

       ManagementScope theManagementScope = new ManagementScope("root\\wmi");

       ObjectQuery theObjectQuery = new ObjectQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE active=true");

       ManagementObjectSearcher theQuery = new ManagementObjectSearcher(theManagementScope, theObjectQuery);

       try

       {

          //ManagementObjectCollection theResults = theQuery.Get();

          foreach(ManagementObject currentObject in theQuery.Get())

          {

             theSignalStrength = theSignalStrength + Convert.ToDouble(currentObject["Ndis80211ReceivedSignalStrength"]);

          }

       }

       catch (Exception e)

       {

          //handle

       }

     

       return Convert.ToDouble(theSignalStrength);

    }

    Tuesday, September 12, 2006 10:00 PM
    Moderator

All replies

  • Can you convert that to C#?
    Tuesday, September 12, 2006 8:03 PM
  • try this:

    private double RetrieveSignalString()

    {

       double theSignalStrength = 0;

       ConnectionOptions theConnectionOptions = new ConnectionOptions();

       ManagementScope theManagementScope = new ManagementScope("root\\wmi");

       ObjectQuery theObjectQuery = new ObjectQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE active=true");

       ManagementObjectSearcher theQuery = new ManagementObjectSearcher(theManagementScope, theObjectQuery);

       try

       {

          //ManagementObjectCollection theResults = theQuery.Get();

          foreach(ManagementObject currentObject in theQuery.Get())

          {

             theSignalStrength = theSignalStrength + Convert.ToDouble(currentObject["Ndis80211ReceivedSignalStrength"]);

          }

       }

       catch (Exception e)

       {

          //handle

       }

     

       return Convert.ToDouble(theSignalStrength);

    }

    Tuesday, September 12, 2006 10:00 PM
    Moderator
  • theSignalStrength is not defined in your code.  What is it supposed to be?

    I tried changing it to theSignalString.

    Also, currentObject is not a method.  Is it supposed to be currentObject.GetPropertyValue("*****") or another method in this variable?

    Tuesday, September 12, 2006 11:46 PM
  • my bad, indeed it should be theSignalStrength - not string so replace all theSignalString to theSignalStrength (including the variable declaration)

    as for the last error, do this:

     

    theSignalStrength = theSignalStrength + Convert.ToDouble(currentObject["Ndis80211ReceivedSignalStrength"]);

     

     

    Tuesday, September 12, 2006 11:52 PM
    Moderator
  • Do I convert this to a string?

    i.e.

    label1.Text = RetreiveSignalStrength().ToString();

    Tuesday, September 12, 2006 11:58 PM
  • to display it in a label or a text box then yes
    Wednesday, September 13, 2006 12:01 AM
    Moderator
  • I get -104. How is it supposed to be displayed?
    Wednesday, September 13, 2006 1:30 AM
  • there could be a problem with the query perhaps or that may be the signal strength found, as I said I just translated the code for you into C#

    What happens if you step through the debugger and look at the locals/find out what the variable's have been set to, such as the currentObject["Ndis80211ReceivedSignalStrength"]) ??

    Wednesday, September 13, 2006 1:48 AM
    Moderator
  • There is nothing in locals.

    Your translation might be working though;  It has gone between -104 and -96.

    Wednesday, September 13, 2006 4:30 PM
  • Hi!

    any idea how to convert those codes into C++?

    Thanx
    Tuesday, July 31, 2007 3:14 PM
  • i have managed to do this code...and i used a 5 sec timer to get the values...i am very near to the Accespoint so i am getting strong signals of  : -188, -196, or sometimes -148..

    the thing is that i want to show these signals in the progressBar and also on a label in the form of percentage...

    how is this possible?
    Death-Code
    Tuesday, August 26, 2008 7:59 AM
  • does it works on windows vista?
    Monday, September 13, 2010 11:47 AM
  • I tried to run this code in C# 2010 and 2008 express. Get the following error:

    Error 1 The type or namespace name 'ConnectionOptions' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Administrator\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.cs 31 13 WindowsFormsApplication1


    But I've included the System.Management:

    using System.Management;

    Any ideas?


    - Stig
    Thursday, February 03, 2011 4:13 PM
  • Just to help you understand the numbers, -104 to -96 is a good range for signal strengths. These are in dB (m or w, I dont know which). By the way, -174 is the rf level of the universe back ground noise. The strength gets better as you go toward 0.

    Saturday, March 19, 2011 2:20 PM
  • I had an issue when using System.Management at first as it seems the default value was just to include System.Management.Instrumentation.  When I added System.Management as a reference to my project it cleared the errors I was having.
    Tuesday, July 12, 2011 3:55 AM