Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Wifi Signal Strength

I'm trying to get the strength of the connected wifi signal using c++ on a Windows 7 machine.

I can get a value for the strength of the signal using the command WlanGetAvailableNetworkList but the value returned is not granular enough for our requirements. Basically as you move away from the Wifi router the value jumps in increments of 20% (99% -> 80% -> 60% etc).

For the application we are developing we really need a more accurate value. I know it's possible as I have seen apps in windows displaying accurate dBm values for signal strength...

If anyone has any suggestions they would be greatly appreciated!

dwResult = WlanGetAvailableNetworkList(hClient,&pIfInfo->InterfaceGuid,0,NULL,&pBssList);

if (dwResult != ERROR_SUCCESS) {
    wprintf(L"WlanGetAvailableNetworkList failed with error: %u\n", dwResult);
    dwRetVal = 1;

} else {

    for (j = 0; j < pBssList->dwNumberOfItems; j++) {
        pBssEntry = (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j];

        if ((pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED ) != 0 ){

            if (pBssEntry->wlanSignalQuality == 0)
                iRSSI = -100;
            else if (pBssEntry->wlanSignalQuality == 100)   
                iRSSI = -50;
            else
                iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);    

            wprintf(L"  Signal Quality[%u]:\t %u (RSSI: %i dBm)\n", j, 
                pBssEntry->wlanSignalQuality, iRSSI);
        }
}
like image 380
flinthart Avatar asked Oct 09 '13 21:10

flinthart


People also ask

What is a good signal strength for WiFi?

-50 dBm: This is considered an excellent signal strength. -60 dBm: This is a good signal strength. -67 dBm: This is a reliable signal strength. This is the minimum for any online services that require a reliable connection and Wi-Fi signal strength.

How do I check WiFi strength?

Use a Smartphone or Tablet Look under a Settings, Wi-Fi, or Network menu. For example, in the settings on a Google Pixel with Android 10, select Network & internet, select the Wi-Fi you're using, and then select the gear icon next to the network you're connected to. There you can see the signal strength.

What is good WiFi signal strength Mbps?

The FCC says the best ISPs for two or more connected devices and moderate to heavy internet use should offer at least 12 megabits per second (Mbps) of download speed. For four or more devices, 25 Mbps is recommended.


1 Answers

Ok after continuing research online I managed to patch together a way that works for me. From what I've read - there are many different ways of obtaining the RSSI - but this method, while maybe a little cumbersome, worked well for our needs...

I'm using the command WlanGetNetworkBssList, and then getting the RSSI value directly from the returned PWLAN_BSS_ENTRY.

I found it is important to call WlanScan each time before querying WlanGetNetworkBssList, otherwise the returned value doesn't change with any sort of regularity.

HANDLE hClient;
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfConnInfo = NULL;
PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;

PWLAN_BSS_LIST pBssList=NULL;
PWLAN_BSS_ENTRY  pBssEntry=NULL;
WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;

DWORD dwResult = 0;
DWORD dwMaxClient = 2;         
DWORD dwCurVersion = 0;
DWORD connectInfoSize = sizeof(WLAN_CONNECTION_ATTRIBUTES);

int i;

// Initialise the Handle
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) 
{    
    return 0;
}

// Get the Interface List
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) 
{    
    return 0;
}

//Loop through the List to find the connected Interface
PWLAN_INTERFACE_INFO pIfInfo = NULL;
for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) 
{
    pIfInfo = (WLAN_INTERFACE_INFO *) & pIfList->InterfaceInfo[i];    
    if (pIfInfo->isState == wlan_interface_state_connected) 
    {
        pIfConnInfo = pIfInfo;
        break;
    }
}

if ( pIfConnInfo == NULL )
    return 0;

// Query the Interface
dwResult = WlanQueryInterface(hClient,&pIfConnInfo->InterfaceGuid,wlan_intf_opcode_current_connection,NULL,&connectInfoSize,(PVOID *) &pConnectInfo,&opCode);
if (dwResult != ERROR_SUCCESS) 
{    
    return 0;
}

// Scan the connected SSID
dwResult = WlanScan(hClient,&pIfConnInfo->InterfaceGuid,&pConnectInfo->wlanAssociationAttributes.dot11Ssid,NULL,NULL);
if (dwResult != ERROR_SUCCESS) 
{    
    return 0;
}

// Get the BSS Entry
dwResult = WlanGetNetworkBssList(hClient,&pIfConnInfo->InterfaceGuid,&pConnectInfo->wlanAssociationAttributes.dot11Ssid,dot11_BSS_type_infrastructure,TRUE,NULL,&pBssList);

if (dwResult != ERROR_SUCCESS) 
{    
    return 0;
}

// Get the RSSI value
pBssEntry=&pBssList->wlanBssEntries[0];
return pBssEntry->lRssi;
like image 191
flinthart Avatar answered Sep 26 '22 01:09

flinthart