0
votes

I want to connect an android device over bluetooth with matlab for exchanging data between matlab and my own android app. But I can't connect via 'Instrument Control'-Toolbox with my android devices. Why?


scan and connect android device First I scaned for all available devices and then tried to connect (with the "connect"-button) with android.


I searched and it says:

So I read the technical spez. from my devices and I can't find that they support the needed SPP bluetooth profile.

  • Samsung Galaxy Young 2 (SM-G 130HN):
    Bluetooth®-Profile: HSP, OPP, SAP, A2DP, PBAP, HFP, AVRCP, DI, HID, HOGP, PAN, MAP
    tech spez. galaxy young
  • Samsung Galaxy S Advance:
    Bluetooth Profiles: GAP, SSP, SDAP, HSP, HFP, A2DP, SAP, OPP, PBAT, MAP, AVRCP, HID
    tech spez. galaxy s
  • HTC One M7:
    Common profiles: HSP [headset], HFP [hands-free], A2DP [stereo audio], AVRCP [media control], HID [peripherals]
    tech spez. HTC One M7

But in the android documentation it says:

  • The most common type of Bluetooth socket is RFCOMM, which is the type supported by the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth. It is also known as the Serial Port Profile (SPP).
    support SPP profile in android

So I think android itself support SPP, but not my used devices?
Is there no way to connect one of these phones via bluetooth with matlab?
Which android devices are working?

1

1 Answers

0
votes

Solution

Here 'activate bluetooth spp in android' it says:

  • On the Android phone you will probably need to run an application that initiates the service over SPP.

You need to listen for incoming connection requests, therefor you should use this function:

listenUsingRfcommWithServiceRecord(String, UUID)

Here you can find some examples:


Code example

final Thread connect = new Thread(new Runnable() {
            @Override
            public void run() {
                BluetoothServerSocket serverSocket;

                BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
                UUID sppUUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

                        BluetoothSocket bluetoothSocket = null;

                        try {

                           serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord("your app name", sppUUID);
                           bluetoothSocket = serverSocket.accept(); // blocking call, until a connection is established.
                           Log.i("TAG", "serverSocket accept");

                        } catch (IOException e) {
                            Log.e("TAG", "IOException");
                        }

                        // If a connection was accepted
                        if (bluetoothSocket != null) {
                            // Do work to manage the connection (in a separate thread)
                            manageConnectedSocket(bluetoothSocket);
                        }

            }
        });
connect.start();

My fault was to think I can connect matlab and android without an own app, just with the android 'bluetooth' connection part in the settings.