0

So I want to connect to a bluetooth module(RN-42) using my android phone. I know the MAC address, but I don't know much about UUID. First of all, do I need the UUID of the device I'm connecting to or am I giving that device the UUID of my phone?

Right now my code goes something like this:

 BluetoothDevice device = bluetooth.getRemoteDevice("00:06:66:43:40:70");
                        BluetoothSocket tmp = null;
                        BluetoothSocket mmSocket = null;

                        try {
                            tmp = device.createRfcommSocketToServiceRecord(UUID);
                        } catch (IOException e) {
                            output = "Connecting to device failed!\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                        }
                        mmSocket = tmp;

                        try
                        {
                            mmSocket.connect();
                        } catch (IOException e)
                        {
                            output = "Connect() error\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                            error = true;
                        }

                        if(!error) {
                            changeScreen(1);
                        }
                        else
                        {
                            output = "Failure :C\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                        }

The purpose is to control a RC-car by sending data from my android app through the bluetooth module an into a picaxe processor. which has a program I've already written that controls the car depending on the data it receives.

1N07
  • 123
  • 7

1 Answers1

0

Okay the whole problem was that I didn't understand wholly how to get the UUID and what UUID to use. So what I'm using is the phones UUID (I assume). And how I get it is with this line:

UUID uuid = device.getUuids()[0].getUuid();

Thanks to: NullPointer Exception on socket.connect() Galaxy Tab 2 running Android 4.04

Community
  • 1
  • 1
1N07
  • 123
  • 7