Mobile development – a WiFi signal strength indicator

Here is one more windows mobile taskbar addon. I have seen many people are interested in these small widgets. This one shows the signal strength of the current associated access point in your taskbar.

The code is the same as with the other taskbaraddons you find here, only the code for wireless signal strength has been added. Oh, yes, and this addon uses small bitmaps to show the signal strength.

To get the signal strength I use part of PeekPocket code submission at CodeProject. I only need the name of the first wireless adapter.

CWifiPeek m_wp;
TCHAR* szAdapterName=new TCHAR[64];

ULONG GetCurrentValue(){
    WCHAR buf[1024];
    DWORD dwSize;
    dwSize=sizeof(buf);
    if(false == m_wp.GetAdapters(buf, dwSize) || dwSize == 0)
    {
        return UNKNOWERROR;
    }
    else{
        //we are only interested in first returned name
        wsprintf(szAdapterName, L"%s", buf);
        int iRSSI=0;
        int iRes = GetSignalStrength(szAdapterName, &iRSSI);
        if(iRes == ERROR_SUCCESS){
            return iRSSI;
        }
        else{
            return LOADLIBFAILED;
        }
    }
}

(http://www.codeproject.com/KB/windows/PeekPocket.aspx)

Then the signal strength is queried using another code snippet:

INT GetSignalStrength(TCHAR *ptcDeviceName, INT *piSignalStrength)
{
    PNDISUIO_QUERY_OID queryOID;
    DWORD dwBytesReturned = 0;
    UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)+sizeof(DWORD)];
    HANDLE ndisAccess = INVALID_HANDLE_VALUE;
    BOOL retval;
    INT hr;

    // Attach to NDISUIO.
    ndisAccess = CreateFile(NDISUIO_DEVICE_NAME, 0, 0, NULL,
    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    INVALID_HANDLE_VALUE );

    if (ndisAccess == INVALID_HANDLE_VALUE)
        return -1;

    // Get Signal strength
    queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
    queryOID->ptcDeviceName = ptcDeviceName;
    queryOID->Oid = OID_802_11_RSSI;

    retval = DeviceIoControl(ndisAccess,
    IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), &dwBytesReturned, NULL);

    if (retval && piSignalStrength)
    {
        hr = 0;
        *piSignalStrength = *(DWORD *)&queryOID->Data;
    }
    else
    {
        hr = -2;
    }

    CloseHandle(ndisAccess);

    return(hr);
}

(http://www.pcreview.co.uk/forums/thread-1306359.php)

Downloads

[Download not found] TaskbarAddon5 (2225 downloads )

4 Comments

  1. John says:

    I see this is an old post, so hope someone is still active. I need to get the signal strength using vb .net on a pocketpc running mobile 6.5. Any ideas/sample code would be appreciated

  2. josef says:

    I am sorry, but retrieving the signal strength may vary from device to device and depends on the WiFi module and drivers used on the device. There is only one ‘standard’ (but bad) supplicant called MS ZeroConfig. If you are luckky, your device comes with wzcsapi.dll and you can follow this: http://msdn.microsoft.com/en-us/library/ee495676%28v=winembedded.60%29.aspx to get RSSI etc.

    regards

    Josef

  3. I’m not sure why but this weblog is loading incredibly slow for me. Is anyone else having this problem or is it a issue on my end? I’ll check back later on and see if the problem still exists.

  4. josef says:

    Hi

    I also noticed that on some posts and found the javascript syntax highlight code executes slowly on some browsers.
    I am not sure if I should disable wpsyntax and we will see simple preformatted code lines or not and have some users getting a slow rendering on there browser.

    ~josef

Leave a Reply