Como enviar dados através de um link Bluetooth Low Energy (BLE)?
Eu sou capaz de descobrir, conectar ao bluetooth.
Código fonte---
Conecte via bluetooth ao dispositivo remoto:
//Get the device by its serial number
bdDevice = mBluetoothAdapter.getRemoteDevice(blackBox);
//for ble connection
bdDevice.connectGatt(getApplicationContext(), true, mGattCallback);
Gatt CallBack para status:
private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
//Connection established
if (status == BluetoothGatt.GATT_SUCCESS
&& newState == BluetoothProfile.STATE_CONNECTED) {
//Discover services
gatt.discoverServices();
} else if (status == BluetoothGatt.GATT_SUCCESS
&& newState == BluetoothProfile.STATE_DISCONNECTED) {
//Handle a disconnect event
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
//Now we can start reading/writing characteristics
}
};
Agora, quero enviar comandos para o dispositivo BLE remoto, mas não sei como fazer isso.
Depois que o comando é enviado ao dispositivo BLE, o dispositivo responde respondendo os dados que meu aplicativo pode receber.