6

我正在尝试在 Windows 7 机器上使用 c++ 获取连接的 wifi 信号的强度。

我可以使用命令获取信号强度的值,WlanGetAvailableNetworkList但返回的值对于我们的要求来说不够精细。基本上,当您离开 Wifi 路由器时,值会以 20% 的增量跳跃(99% -> 80% -> 60% 等)。

对于我们正在开发的应用程序,我们确实需要一个更准确的值。我知道这是可能的,因为我在窗口中看到应用程序显示准确的信号强度 dBm 值......

如果有人有任何建议,他们将不胜感激!

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);
        }
}
4

2 回答 2

5

好的,在继续在线研究之后,我设法拼凑出一种适合我的方式。根据我的阅读 - 有许多不同的方法可以获得 RSSI - 但是这种方法虽然可能有点麻烦,但很适合我们的需求......

我正在使用命令 WlanGetNetworkBssList,然后直接从返回的 PWLAN_BSS_ENTRY 中获取 RSSI 值。

我发现每次在查询 WlanGetNetworkBssList 之前调用 WlanScan 很重要,否则返回的值不会随任何规律性变化。

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;
于 2013-10-10T18:26:29.933 回答
1

wlanSignalQuality 是 RSSI 的插值。看看这个答案问题,了解如何直接获取 RSSI:

从 Windows 获取 Rssi 值

于 2013-10-09T21:47:32.523 回答