La compréhension des Caractéristiques de Bluetooth de Basse Énergie pour Android
J'essaie simplement de lire et d'Écrire Bonjour tout le Monde, à partir d'un galaxy S3 à un blueradio dongle qui est connecté à un port série virtuel. mais je suis
Unhandled exception: java.lang.NullPointerException
lorsque j'ai jamais appel
gatt.readCharacteristic(characteristic);
Je l'utilise pour définir le caractère
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);
L'UUID j'ai pris de la LogCat quand j'ai appelé discoverServices() comme
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
C'est là que je ne sais pas si je le fais je bien, je ne sais pas comment pour obtenir le bon UUID pour une caractéristique et un service
Beloiw est ma fonction de Callback
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);
}
};
Vous devriez probablement commencer par essayer de comprendre précisément ce qui est nul, et puis pourquoi. Si votre poste est littéralement correcte sur la ligne sur laquelle l'exception se produit, alors votre "gatt" l'objet est null, cependant, il semble probable que n'est pas la ligne précise de l'exception.
J'ai essayé de tout le reste avec le gatt.readCharacteristic(caractéristique); commentée et je n'ai pas cette erreur afin que sa soit mon caractéristique ou le gatt, qui est null
Vous pouvez trouver en vous connectant (ou le débogueur) et à partir de là, procéder à figure out pourquoi. Si, techniquement, si c'est la ligne exacte spécifiée pour l'événement d'exception (et pas seulement une partie de sa pile d'appel), puis seulement gatt pourrait être la valeur null.
J'ai essayé de tout le reste avec le gatt.readCharacteristic(caractéristique); commentée et je n'ai pas cette erreur afin que sa soit mon caractéristique ou le gatt, qui est null
Vous pouvez trouver en vous connectant (ou le débogueur) et à partir de là, procéder à figure out pourquoi. Si, techniquement, si c'est la ligne exacte spécifiée pour l'événement d'exception (et pas seulement une partie de sa pile d'appel), puis seulement gatt pourrait être la valeur null.
OriginalL'auteur justin018 | 2014-01-29
Vous devez vous connecter pour publier un commentaire.
UUID est prédéfini par bluetooth.org il définit le préfixe, par exemple 00001800, la dernière partie de la "0000-1000-8000-00805f9b34fb" sont les mêmes pour tous.
voir la liste des prédéfinis UUID ici.
OriginalL'auteur jp_eagle
Je suis en train de le même chose avec le Blueradio dongle USB.
J'ai trouvé les informations suivantes sur BlueRadio Android exemple de projet. Peut-être que cette info peut être utile à vous
UUID pour PARB SERVICE
Caractéristique UUID pour PARB
Si vous trouver plus d'informations s'il vous plaît partager.
Merci
Jean
OriginalL'auteur John Samathanam