5

Ok, so I have a bluetooth.java class which (i'd hoped) would send my strings.. however whenever I try to send the command my broken toasts just show saying nope. Am I missing something vital? I only have these 2 functions in there..

void openBT() throws IOException {

    UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
    try {
        mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), "Unable to create socket", Toast.LENGTH_LONG).show();
    }
    try {
        mmSocket.connect();
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), "Unable to connect to socket", Toast.LENGTH_LONG).show();
    }
    mmOutputStream = mmSocket.getOutputStream();
    mmInputStream = mmSocket.getInputStream();
}

void sendData2() throws IOException {
    if (BtCommand == "0"){
        msg = "Fan2 Off";
    }
    if (BtCommand == "1"){
        msg = "Fan2 On";
    }

    mmOutputStream.write(msg.getBytes());
}

and these are the only things I set

  BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
String BtCommand;
OutputStream mmOutputStream;
InputStream mmInputStream

I am sure it is the openBT function which is failing, I am paired to a device fine.

1 Answers1

0

Are you sure with selected UUID?

List of UUIDs

Alternatively, try to rework your code. I use 2 threads (1 for connect and second connected and communication)

Majkl
  • 765
  • 1
  • 9
  • 25
  • I am not sure no? I thought this uuid corresponded to all bluetooth devices, when I tried it, I tried between 2 android phones (SONY Z1 AND SONY Z5) – David Hasselhof the 2nd Jan 21 '16 at 11:11
  • I am using 00001112-0000-1000-8000-00805f9b34fb – Majkl Jan 21 '16 at 11:15
  • Some quide : http://stackoverflow.com/questions/13964342/android-how-do-bluetooth-uuids-work http://stackoverflow.com/questions/1953888/bluetooth-rfcomm-sdp-connection-to-a-rs232-adapter-in-android – Majkl Jan 21 '16 at 11:19
  • It's not working still.. no idea why, I have even tried some random bluetooth terminal app's and they don't even connect – David Hasselhof the 2nd Jan 21 '16 at 12:01
  • Try to test it on another phone (can be a problem with hardware or setup) – Majkl Jan 21 '16 at 12:12