Reputation: 117
I am trying to simply read and Write Hello World from an galaxy S3 to a blueradio dongle which is connected to a virtual serial port. but I am getting
Unhandled exception: java.lang.NullPointerException
when ever i call
gatt.readCharacteristic(characteristic);
I use this to define the characteristic
private static final UUID MY_UUID = UUID.fromString("00001801-0000-1000-8000-00805f9b34fb");
private static final UUID charUUID = UUID.fromString("00002a01-0000-1000-8000-00805f9b34fb");
characteristic = gatt.getService(MY_UUID).getCharacteristic(charUUID);
The UUID I took from the LogCat when i called discoverServices() as so
D/BluetoothGatt(7083): discoverServices() - device: EC:FE:7E:11:12:A4
D/BluetoothGatt(7083): onGetService() - Device=EC:FE:7E:11:12:A4 UUID=00001800-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetService() - Device=EC:FE:7E:11:12:A4 UUID=00001801-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetService() - Device=EC:FE:7E:11:12:A4 UUID=0000180f-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetService() - Device=EC:FE:7E:11:12:A4 UUID=da2b84f1-6279-48de-bdc0-afbea0226079
D/BluetoothGatt(7083): onGetCharacteristic() - Device=EC:FE:7E:11:12:A4 UUID=00002a00-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetCharacteristic() - Device=EC:FE:7E:11:12:A4 UUID=00002a01-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetCharacteristic() - Device=EC:FE:7E:11:12:A4 UUID=00002a02-0000-1000-8000-00805f9b34fb
D/BluetoothGatt(7083): onGetCharacteristic() - Device=EC:FE:7E:11:12:A4 UUID=00002a03-0000-1000-8000-00805f9b34fb
This is where Im not sure if I am doing i correctly I dont know how to get the proper UUID for a characteristic and service
Beloiw is my full Callback function
private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
public void testFunction(BluetoothGatt gatt){
Log.d(TAG, "In Test Function");
gatt.readRemoteRssi();
BluetoothGattCharacteristic characteristic;
characteristic = gatt.getService(MY_UUID).getCharacteristic(charUUID);
characteristic.setValue("Hello World");
gatt.readCharacteristic(characteristic);
}
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
gatt.discoverServices();
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.d(TAG, "Services Discovered: "+ status);
//mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Enabling Sensors..."));
/*
* With services discovered, we are going to reset our state machine and start
* working through the sensors we need to enable
*/
testFunction(gatt);
}
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic){
Log.d(TAG, "Characteristic Changed: "+ characteristic.getValue());
}
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status){
Log.d(TAG, "Characteristic Read: "+ status);
}
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status){
Log.d(TAG, "Characteristic Write: "+ status);
}
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Log.d(TAG, "Descriptor Read: "+ status);
}
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Log.d(TAG, "Descriptor Write: "+ status);
}
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status){
Log.d(TAG, "Read Rssi: "+ status);
}
public void onReliableWriteCompleted(BluetoothGatt gatt, int status){
Log.d(TAG, "Reliable Write: "+ status);
}
};
Upvotes: 3
Views: 20340
Reputation: 148
UUID is predefined by bluetooth.org, it defines the prefix, e.g. 00001800, the last part "0000-1000-8000-00805f9b34fb" are same for all.
see the list of predefined UUID here.
Upvotes: 5
Reputation: 1
I'm trying to to the same thing with the Blueradio USB dongle. I found the following info on BlueRadio Android example project. May be this info might be useful to you
UUID for BRSP SERVICE
DA2B84F1627948DEBDC0AFBEA0226079
Characteristic UUID for BRSP
99564A02DC014D3CB04E3BB1EF0571B2 --> Info
A87988B9694C479C900E95DFA6C00A24 --> Mode
BF03260C72054C25AF4393B1C299D159 --> RX
18CDA7844BD3437085BBBFED91EC86AF --> TX(Data sent to Client PC/ANDROID from BLE)
0A1934F524B84F13984237BB167C6AFF --> CTS
FDD6B4D3046D4330BDEC1FD0C90CB43B --> RTS
If you find out more info please share.
Thanks John
Upvotes: 0