Bluetooth SPP between Android and other device, UUID and PIN questions
I'm trying to implement an Android application to receive data from a medical device but I can't get through the discovery process and get the phone and the device paired or connected to each other.
Describing the medical device: The device is using Service Discovery Protocol (SDP) and Serial Port Profile (SPP). It starts an inquiry procedure to discover (up to 10) surrounding access points with matched COD Filter and Service Name. Then it sequentially establishes a connection (using Page Procedure) with the access point by checking the PIN. Once the PIN is matched, the data is uploaded. Upon uploading data the device waits for an acknowledge. The decice is the master and initiates the communication.
I have no control of the medical device. All I can do is to start it and await the procedure described above (after a measurement).
The Android application:
I've started out from the Bluetooth Chat Example on the developer pages. So far I've replaced the UUID with the 00001101-0000-1000-8000-00805f9b34fb
to use SPP and set the Service Name to the appropriate name. I can confirm this seems correct through inspection of the service from a computer. Since the medical device is the one that inquirys and initiates the communication my service is using a BluetoothServerSocket
and the accept()
method to start listening for it.
In the developer pages I've read that UUID must match between the applications trying to communicate. Since I can't set any UUID for the medical device I'm wondering if this is going to be a problem or if it is enough that the medical device is using the SP Profile?
If the Service Name and UUID are correct and the medical device would actually try to connect to my Bluetooth service which is listening for connections, would the Android system prompt me to input the PIN manually to be able to pair the devices (since the medical device has a pre-set PIN)?
I haven't found anything in the Android SDK API that lets me set a PIN for my Bluetooth service (in case this is where it fails), is this possible?
I've read that normally the PIN is generated by the system nowadays and a user confirmation is the only thing needed. I guess not in my system, since the device is a bit older.
I would be greatful if you would like to share some knowledge, hints, guesses of anything related to what I've described above!
Thanks in adv开发者_如何学编程ance, Fredrik
EDIT:
Now I've got the device paired with a bluegiga box and they communicate correctly. Now I'm searching for the criterias to fulfil for the blood pressure device to connect to my phone. I can inspect, from a Linux computer (sdptool search SP
in a terminal), the Bluetooth service provided by the bluegiga and compare this to the Bluetooth service I provide on the Android. These values are what I get:
~$ sdptool search SP
Inquiring ...
Searching for SP on 8C:71:F8:E5:XX:XX . . .
Service Name: 1808130054
Service RecHandle: 0x10003
Service Class ID List:
UUID 128: 00001101-0000-1000-8000-00805f9b34fb
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 13
´
Seaching for SP on 00:07:80:88:XX:XX . . .
Service Name: 1808130054
Service Description: 1808130054
Service RecHandle: 0x10005
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 12
Language Base Attr List:
code_ISO639: 0x656e
enconding: 0x6a
base_offset: 0x100
The first device found is the phone (mac=8C:71...Google Nexus S) and the second (mac=00:07...) is the bluegiga. I notice that there is no Service Description on the Android device. I think the most important difference is in the Service Class ID List. UUID 128 on the Android but a totally different format describing this on the bluegiga.
Is it possible to implement using Service Class IDs with other format than UUID on Android?
Can you manipulate the Service Record registered in the service discovery DB?
Would it be possible to somehow implement towards the BlueZ directly, using native development c/c++?
/Fredrik
If you can provide the name / link to the medical device (if it is a commercial device) it might help to read up its guide to guess more on what might be going on. Here are a few suggestions :
In addition to the Serial Port UUID , each service over the SPP can have a custom specific UUID - example the medical device could look for the service with which it is compatible using this custom-specific UUID.
If the medical device currently connects to a PC or some other access point successfully and transfers data , the you could try read the SDP record of that device and determine what specific UUID in addition to the SPP UUID is in use if any, and use the same in your application also.If the medical device is not able to find your phone / application it could be because it is not discoverable. Android device by default is not discoverable even when you are a server, it will be only connectable and not discoverable, you can try to make it discoverable programetically or through the settings and see if the medical device can find your device. See here - Enabling Discoverability in Android
For PIN pairing , The android device should start the pairing process when a non paired device tries to connect to it, you can try it after getting through the recommendations (1) and (2), PIN pairing is used if one of the devices are prior to version Bluetooth 2.1 , Even with newer devices a 6-digit passkey with some user intervention / confirmation will be required at the phone to allow for the pairing (its is just a good security policy to not allow this to just happen automatically without user intervention) , hopefully pairing will only be require the first time a connection happens, later it will not require any user intervention for subsequent connections.
精彩评论