Reputation: 343
I am trying to capture the (data)reading on Android phone from the 'Bluetooth Health Devices' such as Oximeter, Thermometer, Weighing Scale machine etc. I am able to connect the device to phone but when it goes to read the data it stuck over there only. I am doing the following steps..(Android 2.2) First I am creating socket connection
BluetoothSocket Socket.connect();// for socket connection-----done successfully
BluetoothSocket tmp= device.createRfcommSocketToServiceRecord(MY_UUID);
//here
MY_UUID="00001101-0000-1000-8000-00805F9B34FB";
in read thread
byte[] buffer = new byte[37];// i think here I am not getting exact bytes
int bufferBytes = 0, bufferIndex = 0;
Log.e(TAG, "MESSAGE_READ....");
Communications comms = null;
Bundle bundle = new Bundle();
try {
comms = new Communications();
Log.e(TAG, "After Communications....");
} catch (Exception e) {
Log.e(TAG, "Error in communicaton....");
}
// Keep listening to the InputStream while connected
while (true) {
Log.e(TAG, "Its coming in while");
try {
try {
bufferBytes = mmInStream.read(buffer);// the code stuck here its not going down till health device get off(its directly jump to exception after device get off)
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "bufferBytes error ====== +e.getMessage());
}
//Log.e(TAG, "bufferBytes====== "+bufferBytes);
while (bufferBytes > bufferIndex) {
String[] message = comms.receiveMessage(buffer,
bufferIndex, bufferBytes);
bufferIndex = Integer.parseInt(message[1]);
Log.e(TAG, "bufferIndex====== "+bufferIndex);
if (message[0] != null) {
/*
* Processing message sent by device
*/
StringTokenizer dataInTokens = new StringTokenizer(
message[0]);
if (dataInTokens.hasMoreTokens() == true) {
String token = dataInTokens.nextToken();
Log.e(TAG, "token====== "+token);
if (token.equals("a")) {
int weight = 0;
if (dataInTokens.hasMoreTokens() == true) {
weight = Integer.parseInt(dataInTokens
.nextToken());
// Send a message back to the Activity
msg = mHandler
.obtainMessage(ScaleActivity.MESSAGE_READ);
bundle.putInt(ScaleActivity.WEIGHT,
weight);
msg.setData(bundle);
mHandler.sendMessage(msg);
}
} else if (token.equals("b")) {
int weight = 0;
if (dataInTokens.hasMoreTokens() == true) {
weight = Integer.parseInt(dataInTokens
.nextToken());
// Send a message back to the Activity
msg = mHandler
.obtainMessage(ScaleActivity.MESSAGE_READ);
bundle.putInt(
ScaleActivity.WEIGHT_TO_SAVE,
weight);
msg.setData(bundle);
mHandler.sendMessage(msg);
}
}
}
}
}
And I tried the Android 4.0 HDP Example also.which is available here but our heath devices are not comaptible to hdp. so it is also not working for me.
Upvotes: 0
Views: 2281
Reputation: 31
I am exactly in the same situation. I am able to stablish the connection and create the socket using the SSP profile (UUID 00001101-0000-1000-8000-00805F9B34FB). I have verified that the Bluetooth Health device is exposing the SSP service by executing this reflection code (the method to retrieve device exposed UUIDs is hidden in this API level):
Class<?> cl = Class.forName("android.bluetooth.BluetoothDevice");
Method method = cl.getMethod("getUuids");
Object retval = method.invoke(myBTDevice);
(retval contains an array of valid UUID device services which you can connect to.)
I think the problem is that, before trying to read anything, a set of command/s have to be sent to the device, otherwise the read method will hang forever. I have been googling for some days now trying to figure out this hidden protocol but without success. I have also search by the manufacturer name and model but nothing (DigiFox Fingertip pulse oximeter).
My only hope is that, whith the device a custom software running in windows is provided which successfully communicates with the device and is able to read measures. I may need to use some kind of Bluetooth analyzer or packet sniffer to check the data that is sent to the device before reading anything. If I am able to get it working I will post it here.
Regards.
Upvotes: 1