I have setup a Pi4 using PyBluez to create a Bluetooth server. The client is on an Android phone using Android Studio. So far it is working the way I need to except that I wish to automate the first time connection a little better. At the moment, I must pair the phone with the Raspberry Pi, then in the phone, I display the list of paired devices to choose the right connection. But this list includes haedset, watch, cars, etc etc.

I thought that the UUID was to be used for that purpose but I guess not. Here is the code inside the RPi;

port = 1
server_socket.bind(("", bluetooth.PORT_ANY))
port = server_socket.getsockname()[1]

#uuid = "00001101-0000-1000-8000-00805F9B34FB"
uuid = "f6145c49-446b-4d64-88cd-923db42c8c56"
bluetooth.advertise_service(server_socket, "Test", service_id=uuid, 
                            service_classes=[uuid, bluetooth.SERIAL_PORT_CLASS],

csock1 = server_socket
while True:
    print("Waiting for connection1")
    csock1, client_info = server_socket.accept()
    print("Connected1: ", client_info)
        while True:
            data = csock1.recv(1024)
            if not data:
            ... processing data

        print("1 disconnected")
        c1Connected = False

It doesn't matter what UUID I put, it always connect. And in the Android, I only detect the Bluetooth Class of 0.

Here is the code in Android:

pairedDevices = myBluetooth.getBondedDevices();
ArrayList list = new ArrayList();

if (pairedDevices.size()>0)
    for(BluetoothDevice bt : pairedDevices)
        BluetoothClass btclass = bt.getBluetoothClass();
        int i = btclass.getDeviceClass();
        Log.i("LED", bt.getName()+" "+String.valueOf(i));
        list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address
    Toast.makeText(getApplicationContext(), getString(R.string.bt_dev_not_paired), Toast.LENGTH_LONG).show();

I would really like to list only the RPI that are running my application. How is this possible?

  • Anybody can help me with that?
    – Guytas
    Aug 8 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.