1

I try to dicover bluetooth devices on windows and have some trouble. First the code:

WSAQUERYSET wsaq;
HANDLE hLookup;
LPWSAQUERYSET pwsaResults;
DWORD dwSize;
BOOL bHaveName;
BT_ADDR btAddr;
DWORD dwNameSpace;

pwsaResults = (LPWSAQUERYSET)butuh.buf;
dwSize = sizeof(butuh.buf);

ZeroMemory(&wsaq, sizeof(wsaq));
wsaq.dwSize = sizeof(wsaq);
wsaq.dwNameSpace = NS_BTH;
wsaq.lpcsaBuffer = NULL;

if (WSALookupServiceBegin(&wsaq, LUP_CONTAINERS | LUP_FLUSHCACHE, &hLookup) == SOCKET_ERROR)
{
    printf("WSALookupServiceBegin() failed %d (Maybe no BT Device?) \r\n", WSAGetLastError());
    return FALSE;
}

ZeroMemory(pwsaResults, sizeof(WSAQUERYSET));
pwsaResults->dwSize = sizeof(WSAQUERYSET);
pwsaResults->dwNameSpace = NS_BTH;
pwsaResults->lpBlob = NULL;

while (WSALookupServiceNext(hLookup, LUP_RETURN_NAME | LUP_RETURN_ADDR, &dwSize, pwsaResults) == 0)
{
    // to get the remote address, the btAddr field should be properly cast
    btAddr = ((SOCKADDR_BTH *)pwsaResults->lpcsaBuffer->RemoteAddr.lpSockaddr)->btAddr;

    // Verify the returned name
    bHaveName = (pwsaResults->lpszServiceInstanceName) && *(pwsaResults->lpszServiceInstanceName);

    // Some more info
    dwNameSpace = pwsaResults->dwNameSpace;

    wprintf(L"Device Name: %s \n", pwsaResults->lpszServiceInstanceName);
    wprintf(L"Device Address: 0X%012X \n", btAddr);
    wprintf(L"NAP Address: 0X%04X \n", GET_NAP(btAddr));
    wprintf(L"SAP Address: 0X%08X \n", GET_SAP(btAddr));
    wprintf(L"Name Space: 0X%0X \n \n \n", dwNameSpace);

    memcpy(&list+devices, &btAddr, sizeof(btAddr));
    devices++;
}

if (WSALookupServiceEnd(hLookup) != 0)
    printf("FindingBtDevices(): WSALookupServiceEnd(hLookup) failed with error code %ld\n", WSAGetLastError());

I can discover my phone or an other computer without any problem but I try to work with a bluetooth devkit of Atmel and I'm not able to find it. Atmel SAMB11

If I use the Windows GUI to search a bluetooth device, it's no problem to find the devkit. Any idea what's the problem and how to fix it?

AMD
  • 31
  • 1
  • It's also not possible to find the device with windows 7 over bluetooth. The only way is to use Windows 8.1 / 10 and use the integrated App. This app using the "Universal Windows Platform". The methode to search devices isn't equal with the winsock methode. – AMD Apr 27 '16 at 12:45

0 Answers0