2013-10-09 211 views
4

我試圖讓Windows 7的機器上使用C++所連接的WiFi信號的強度。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); 
     } 
} 

回答

3

好的網上不斷的研究後,我好不容易纔拼湊,對我工作的方式。從我讀過的 - 有很多不同的方式獲取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; 
+0

如果你可以包含'include'的列表...... – Acidic

1

wlanSignalQuality是RSSI的插值。看看如何獲​​得直接的RSSI這樣的回答的問題:

Get Rssi Value From Windows

+0

謝謝Cookie - 我前幾天看過這個。我嘗試以這種方式獲取RSSI值 - 但我不知道如何將其轉換爲dBm。每次運行該程序時,該值都完全不同,每次我調用WlanQueryInterface時,值都會增加32. 5627392,5627424,5627456等... – flinthart

+0

@ flinthart沒有通用轉換,它是一種相對無單位的度量,取決於設備,如果你真的想做任何轉換。 – CookieOfFortune