ItGo.me Focus on IT Recommend

Home > java - Bluetooth communication between Processing Desktop and Android(Not Processing)

java - Bluetooth communication between Processing Desktop and Android(Not Processing)

What I'm doing is communication between

Desktop(Windows 8) Processing(2.2.1) Application <---- Android application(Not made by Processing, it's made on Android Studio)

I need to send data to desktop from android application (one side communication).

From android.. First, I'm getting already paired device. It means that before executing both application, I will pair desktop and android device already. Bluetooth connection and sending outstream is on child thread.

    Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {

            Log.i(TAG, device.getName() + "\n" + device.getAddress());
            targetDevice = device;
            break;
        }
    }else{
        Log.i(TAG, "No paired device found!");
    }

And then, I connect it

    BluetoothSocket tmp = null;

    // Get a BluetoothSocket for a connection with the
    // given BluetoothDevice
    try {
        tmp = targetDevice.createRfcommSocketToServiceRecord(MY_UUID);
        Method m = targetDevice.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
        tmp = (BluetoothSocket) m.invoke(targetDevice, 1);
    } catch (Exception e) {
        Log.e(TAG, "create() failed", e);
    }
    btSocket = tmp;

    if (btSocket != null){
        // Socket is created

        // try to connect the socket
        BluetoothConnectionThread thread = new BluetoothConnectionThread(btSocket);
        thread.start();
    }

From logcat(Log.i), I can see connection is successfully established. It seems that there is no problem on android side.

I'm using Serial Port Protocol UUID which is

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

And from Android side, it's completely ready to write any byte[].. and when I press dummy button on android, device sends dummy bytes to outputstream. I think it has no problem here on Android side..


Now, on desktop processing(Windows 8, processing 2.2.1 - I HAVE TO USE processing 2.0, there is no other option for some reason.), I have no any clue what I have to now.. I searched in google a lot but I could not find any clue. Now, I'm trying to use processing Serial library like

println(Serial.list());

but it gives nothing... So, I tried to initialize Serial object by

Serial port = new Serial(this, "/dev/rfcomm0", 115200);

but it gives error

Error opening serial port /dev/rfcomm0:Port busy

Is there any other way to read socket buffer(instream) which comes from Android on processing desktop?

I am sure that this is not bluetooth driver issue because I installed the recentest driver for my desktop(Qualcomm Atheros AR3012 Bluetooth 4.0 + HS)

Just for reference..desktop is actually laptop with bluetooth(ASUS UX21E) and Android device is Galaxy Tab S(267.2mm, Octa-Core 2560x1600).

I think I have not enough knowledge about bluetooth... Please lead me to some way...

Recommend:Bluetooth communication between Android and Arduino using Processing

ssing for Android. I have success transferring data from the Android to the Arduino with serial.begin(9600). And I have success transferring data from the Arduino to the Android by using SoftwareSerial in the Arduino program and bluetooth.b

oriUlr:http://stackoverflow.com/questions/33731641/bluetooth-communication-between-processing-desktop-and-androidnot-processing

------splitte line----------------------------