'Distinguishing correct bluetooth device application

I have a bluetooth mobile application that has two different modes. One of them behaves as a client and another server. Assume you are in a room and there are 20 device. One of them is a server and anothers are clients and their bluetooth is turned on. Client should connect to appropriate device -device may be different in each time so mac address may be different as well- even if there are another unwanted servers. I used to device name due to find the correct device but sometimes device name is returned as null. What can I use to find the correct device ? And that is real time application, delay is also so important factor for me.



Solution 1:[1]

You can Advertise a custom UUID

    UUID uuid = UUID.fromString("0000000-0000-0000-0000-000000000001");

    AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
    ParcelUuid parcelUuid = new ParcelUuid(uuid);
    dataBuilder.addServiceUuid(parcelUuid);

    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();

    int mAdvertiseMode = AdvertiseSettings.ADVERTISE_MODE_BALANCED;
    int mAdvertiseTxPowerLevel = AdvertiseSettings.ADVERTISE_TX_POWER_HIGH;
    settingsBuilder.setAdvertiseMode(mAdvertiseMode);
    settingsBuilder.setTxPowerLevel(mAdvertiseTxPowerLevel);
    settingsBuilder.setConnectable(true);

    bta.getBluetoothLeAdvertiser().startAdvertising(settingsBuilder.build(), dataBuilder.build(), new AdvertiseCallback() {
    });

and read that from the receiver

BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
        scanner.startScan(new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                int rssi = result.getRssi();
                if (result.getScanRecord() != null && result.getScanRecord().getServiceUuids() != null) {
                    for (ParcelUuid uuid : result.getScanRecord().getServiceUuids()) {
                        String uuid = uuid.toString();
                    }
                }
            }
        });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 julian