0

BLE デバイスにデータを送信する Android アプリを開発しています。BLEデバイスに接続すると、サービスと特性を発見し、これを取得しました

onGetService() - Device=D8:80:39:F0:03:6E UUID=00001800-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=0000180a-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=49535343-fe7d-4ae5-8fa9-9fafd205e455
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a00-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a01-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a04-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a29-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a24-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a25-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a27-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a26-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a28-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a23-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a2a-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-6daa-4d02-abf6-19569aca69fe
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-aca3-481c-91ec-d85e28a60318
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-1e4d-4bd9-ba61-23c647249616
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-8841-43f4-a8d4-ecbe34729bb3
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-026e-3a9b-954c-97daef17e26e
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onSearchComplete() = Device=D8:80:39:F0:03:6E Status=0

私のデバイスには3つのサービスと16の特性があると思います(各サービスには異なる特性があります)。問題は、charを送信する必要があるときです。このコードを使用します

 public void writeCustomCharacteristic(int value) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    /*check if the service is available on the device*/
    BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("00001800-0000-1000-8000-00805f9b34fb"));
    if(mCustomService == null){
        Log.w(TAG, "Custom BLE Service not found");
        return;
    }
    /*get the read characteristic from the service*/
    BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00002a04-0000-1000-8000-00805f9b34fb"));
    mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
    if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
        Log.w(TAG, "Failed to write characteristic");
    }
}

問題は、どのサービスと特性を使用する必要があるかということです。私は私が発見したものを使用します。単純な char を BLE デバイスに送信し、UART 型インターフェイスから受信したいと考えています。

4

1 に答える 1