Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
I am using the Android Bluetooth Chat Sample, and I was wondering how and where I should add codes to able to connect to multiple devices? On Wednesday, December 22, 2010 8:57:53 PM UTC-6, Kristopher Micinski wrote: Many people have this problem, this implements a Bluetooth Piconet, this is why this is using seven different UUIDs for the Bluetooth socket. I went through this example and saw how it is implemented, it is similar to how we implement this client/server functionality in a few of our applications in our research. I believe the key to getting this to work is inthe mUuid list. Take a close look at what this is doing? for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { myBSock = getConnectedSocket(myBtServer, mUuid.get(i)); if (myBSock == null) { try { Thread.sleep(200); } catch (InterruptedException e) { Log.e(TAG, InterruptedException in connect, e); } } } } What this code does is looks to connect to the device, but how does it do so? It tries the socket multiple times, using multiple UUIDs for the session. In essence it means that we can use UUID only *once*. So instead this application implements using seven UUIDs, then the server listens and accepts each UUID on the server side, this is what is done with the following code: for (int i = 0; i Connection.MAX_SUPPORTED maxConnections 0; i++) { BluetoothServerSocket myServerSocket = mBtAdapter .listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i)); BluetoothSocket myBSock = myServerSocket.accept(); myServerSocket.close(); // Close the socket now that the // connection has been made. String address = myBSock.getRemoteDevice().getAddress(); mBtSockets.put(address, myBSock); mBtDeviceAddresses.add(address); Thread mBtStreamWatcherThread = new Thread(new BtStreamWatcher(address)); mBtStreamWatcherThread.start(); mBtStreamWatcherThreads.put(address, mBtStreamWatcherThread); maxConnections = maxConnections - 1; if (mCallback != null) { mCallback.incomingConnection(address); } } Now, on the client side of things what is done? The client does not know how many active connections the server currently has. If we have some agreed upon order that the clients must use we can simply use this, however, in our case, we simply just try *each UUID* in sequence until we find the right one. Hopefully this helps you, and everyone else who has questions about this problem, feel free to email me with problems you have. Short version: -- Use multiple UUIDs, you can only use one at once. So define seven (max for piconet usage) and try each one until you find the right one. Thanks, Kristopher Micinski Michigan State University 2010/12/22 苗鹏 mp870...@gmail.com I looked at the FBTClickLinkCompete'source, for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { myBSock = getConnectedSocket(myBtServer, mUuid.get(i)); if (myBSock == null) { try { Thread.sleep(200); } catch (InterruptedException e) { Log.e(TAG, InterruptedException in connect, e); } } } } This code fragment shows a client that trys to connect the server... The sample of SDK(BluetoothChat) used same code except for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { I don't understand why? what'more, it can't connect to multiple devices at the same time! Thanks!!! 2010/12/21 Morrison Chang morrison.ch...@gmail.com Look at http://code.google.com/p/apps-for-android/ Specifically the code for BTClickLinkCompete for a sample of Bluetooth connectivity. http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete I think the air hockey sample supports 4 other devices along with the server device. -Morrison On Dec 20, 3:37 am, 苗鹏 mp870...@gmail.com wrote: could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏
[android-developers] Re: Android bluetooth api connect to multiple devices at the same time
i have tried this solution.. but it does not work. it crashes on the third device connction. We get an error like this 05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): IOException in getConnectedSocket 05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): java.io.IOException: Service discovery failed On Saturday, December 18, 2010 6:25:08 PM UTC+4, 枫儿 wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
That seems to be a general problem, and it's typically with device hardware, rather than anything you're doing. Basically, may manufacturers cheap out on the BT adapters, (or the lower level APIs aren't working properly). It sucks, but it's nothing you're doing, if I'm understanding your description correctly. kris On Thu, May 17, 2012 at 8:36 AM, koladoo nitish kola...@gmail.com wrote: i have tried this solution.. but it does not work. it crashes on the third device connction. We get an error like this 05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): IOException in getConnectedSocket 05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): java.io.IOException: Service discovery failed On Saturday, December 18, 2010 6:25:08 PM UTC+4, 枫儿 wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
I looked at the FBTClickLinkCompetehttp://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete 'source, for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { myBSock = getConnectedSocket(myBtServer, mUuid.get(i)); if (myBSock == null) { try { Thread.sleep(200); } catch (InterruptedException e) { Log.e(TAG, InterruptedException in connect, e); } } } } This code fragment shows a client that trys to connect the server... The sample of SDK(BluetoothChat) used same code except for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { I don't understand why? what'more, it can't connect to multiple devices *at the same time*! Thanks!!! 2010/12/21 Morrison Chang morrison.ch...@gmail.com Look at http://code.google.com/p/apps-for-android/ Specifically the code for BTClickLinkCompete for a sample of Bluetooth connectivity. http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete I think the air hockey sample supports 4 other devices along with the server device. -Morrison On Dec 20, 3:37 am, 苗鹏 mp870...@gmail.com wrote: could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
Many people have this problem, this implements a Bluetooth Piconet, this is why this is using seven different UUIDs for the Bluetooth socket. I went through this example and saw how it is implemented, it is similar to how we implement this client/server functionality in a few of our applications in our research. I believe the key to getting this to work is inthe mUuid list. Take a close look at what this is doing? for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { myBSock = getConnectedSocket(myBtServer, mUuid.get(i)); if (myBSock == null) { try { Thread.sleep(200); } catch (InterruptedException e) { Log.e(TAG, InterruptedException in connect, e); } } } } What this code does is looks to connect to the device, but how does it do so? It tries the socket multiple times, using multiple UUIDs for the session. In essence it means that we can use UUID only *once*. So instead this application implements using seven UUIDs, then the server listens and accepts each UUID on the server side, this is what is done with the following code: for (int i = 0; i Connection.MAX_SUPPORTED maxConnections 0; i++) { BluetoothServerSocket myServerSocket = mBtAdapter .listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i)); BluetoothSocket myBSock = myServerSocket.accept(); myServerSocket.close(); // Close the socket now that the // connection has been made. String address = myBSock.getRemoteDevice().getAddress(); mBtSockets.put(address, myBSock); mBtDeviceAddresses.add(address); Thread mBtStreamWatcherThread = new Thread(new BtStreamWatcher(address)); mBtStreamWatcherThread.start(); mBtStreamWatcherThreads.put(address, mBtStreamWatcherThread); maxConnections = maxConnections - 1; if (mCallback != null) { mCallback.incomingConnection(address); } } Now, on the client side of things what is done? The client does not know how many active connections the server currently has. If we have some agreed upon order that the clients must use we can simply use this, however, in our case, we simply just try *each UUID* in sequence until we find the right one. Hopefully this helps you, and everyone else who has questions about this problem, feel free to email me with problems you have. Short version: -- Use multiple UUIDs, you can only use one at once. So define seven (max for piconet usage) and try each one until you find the right one. Thanks, Kristopher Micinski Michigan State University 2010/12/22 苗鹏 mp870...@gmail.com I looked at the FBTClickLinkCompete'source, for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { myBSock = getConnectedSocket(myBtServer, mUuid.get(i)); if (myBSock == null) { try { Thread.sleep(200); } catch (InterruptedException e) { Log.e(TAG, InterruptedException in connect, e); } } } } This code fragment shows a client that trys to connect the server... The sample of SDK(BluetoothChat) used same code except for (int i = 0; i Connection.MAX_SUPPORTED myBSock == null; i++) { for (int j = 0; j 3 myBSock == null; j++) { I don't understand why? what'more, it can't connect to multiple devices at the same time! Thanks!!! 2010/12/21 Morrison Chang morrison.ch...@gmail.com Look at http://code.google.com/p/apps-for-android/ Specifically the code for BTClickLinkCompete for a sample of Bluetooth connectivity. http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete I think the air hockey sample supports 4 other devices along with the server device. -Morrison On Dec 20, 3:37 am, 苗鹏 mp870...@gmail.com wrote: could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android bluetooth api connect to multiple devices at the same time
Look at http://code.google.com/p/apps-for-android/ Specifically the code for BTClickLinkCompete for a sample of Bluetooth connectivity. http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete I think the air hockey sample supports 4 other devices along with the server device. -Morrison On Dec 20, 3:37 am, 苗鹏 mp870...@gmail.com wrote: could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Android bluetooth api connect to multiple devices at the same time
I will have a try! Thanks ! 2010/12/21 Morrison Chang morrison.ch...@gmail.com Look at http://code.google.com/p/apps-for-android/ Specifically the code for BTClickLinkCompete for a sample of Bluetooth connectivity. http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete I think the air hockey sample supports 4 other devices along with the server device. -Morrison On Dec 20, 3:37 am, 苗鹏 mp870...@gmail.com wrote: could you share me your code?Thanks! 2010/12/20 James 030440...@163.com of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.comandroid-developers%2Bunsubs cr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android bluetooth api connect to multiple devices at the same time
of course you can, On Dec 18, 9:25 am, 苗鹏 mp870...@gmail.com wrote: It is possible to connect simultaneously to multiple bluetooth devices? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en