2016-12-07 5 views
6

をcharactersticへの書き込み中に、私は次のように使用しています私は、BLE device.Iに読み取りおよび書き込み操作を実行しようとしていますライブラリreact-native-ble-managerブレ-取得エラーコード - 128

を反応させるのに成功し、読み取り操作を行うことが可能です。しかし、私はBLEデバイスに書き込み中にエラーコード128を取得しています。

最初、私は特性のための通知を有効にしています -

const base64String = new Buffer('0x00B00050D0', 'hex').toString('base64'); 

    BleManager.write(peripheralId, serviceId, characteristicId, base64Value) 

書き込み操作のリターンエラーコード-128 - base64文字列に
変換する '進' 値 -

BleManager.startNotification(peripheralId, serviceId, characteristicId) 

書き込みは、このようなものです

:(

UPDATE - これは、通知を開始し、付加価値 完全なファイルを書き込むためのコードスニペットでは、これは、リソースがないエラーですhere- BluetoothLeService.java

public void writeCharacteristic(BleCharacteristic bleCharacteristic, String inputValue) { 

    if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 

    if (!bleCharacteristic.isNotificationStarted()) { 
     Log.w(TAG, "Notification not started please start notification"); 
     return; 
    } 

    BluetoothGattCharacteristic bluetoothGattCharacteristic = bleCharacteristic.getBluetoothGattCharacteristic(); 
    bluetoothGattCharacteristic.setValue(inputValue); 
    mBluetoothGatt.writeCharacteristic(bluetoothGattCharacteristic); 
} 

public void setCharacteristicNotification(BleCharacteristic bleCharacteristic) { 
    if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
     Log.w(TAG, "BluetoothAdapter not initialized"); 
     return; 
    } 
    boolean enable = !bleCharacteristic.isNotificationStarted(); 
    Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" 
      + bleCharacteristic.getUUID().toString() + ", enable=" + enable + ")"); 
    BluetoothGattCharacteristic characteristic = mBluetoothGatt.getService(bleCharacteristic.getServiceUUID()).getCharacteristic(bleCharacteristic.getUUID()); 
    mBluetoothGatt.setCharacteristicNotification(characteristic, enable); 
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00}); 
    boolean result = mBluetoothGatt.writeDescriptor(descriptor); 
    bleCharacteristic.setNotificationStarted(result); 
    Log.d(TAG, "setCharacteristicNotification(device=" + mBluetoothDeviceAddress + ", UUID=" 
      + bleCharacteristic.getUUID().toString() + ", enabled=" + result + ")"); 
} 
+0

:ここ

は一例です。 0_r1/stack/include/gatt_api.h#49)、エラーは 'GATT_NO_RESOURCES'を意味します。それがどういう意味なのかわからない – Distjubo

+0

奇妙なことに、 'write'の代わりに' writeWithoutResponse'を使うとどうなりますか?これで問題は解決しますか? – Distjubo

+0

@Distjubo writeWithoutResponseで試してみましたが、エラーは発生しませんでしたが、問題は です。 を書き込んだ後に応答が必要です。2.特性型がwriteWithoutResponseではありません。 – Subham

答えて

2

見つけることができます。あなたはディスクリプタを書きましたか?記述子(BluetoothGattDescriptor)を設定せずにwriteだけを呼び出すと、このエラーが発生します。 [本](https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1によれば

protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"); 

public boolean setCharacteristicNotification(BluetoothDevice device, UUID serviceUuid, UUID characteristicUuid, 
     boolean enable) { 
    if (IS_DEBUG) 
     Log.d(TAG, "setCharacteristicNotification(device=" + device.getName() + device.getAddress() + ", UUID=" 
       + characteristicUuid + ", enable=" + enable + ")"); 
    BluetoothGatt gatt = mGattInstances.get(device.getAddress()); //I just hold the gatt instances I got from connect in this HashMap 
    BluetoothGattCharacteristic characteristic = gatt.getService(serviceUuid).getCharacteristic(characteristicUuid); 
    gatt.setCharacteristicNotification(characteristic, enable); 
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); 
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 }); 
    return gatt.writeDescriptor(descriptor); //descriptor write operation successfully started? 
} 

Source

+0

はい、私はこれと同様にしています。まず、特性の通知と書き込みを有効にします。しかし、常にエラーコード-128を返します。私はすぐに自分のコードを掲載する予定です。 – Subham

+0

さて、最新のコードで投稿を更新したらお知らせください。 – Faraz

+0

私はコードをここにプッシュしています:http://github.com/shubhapp/BleManager/blob/master/Application/src/main/java/com/km2/blemanager/connection/BleConnectionManager.java 今日、私は1つのことを観察しました。初めての書き込みをしようとしているときにステータス128を取得していますが、接続を解除して再び接続するまでステータスは常に0になっています。しかし、私は出力値を受け取ったことがありません – Subham

関連する問題