Android Bluetooth status 133 in onCharacteristicwrite

后端 未结 4 1013
面向向阳花
面向向阳花 2020-12-10 02:40

I\'m new to Android and now doing a simple app that requires writing some data into a peripheral device.

Actually nothing goes wrong in a Samsung GT-S7272C device.

相关标签:
4条回答
  • 2020-12-10 03:07

    I had a similar issue when I tried to write to some characteristic I can't remember though if i got the same error code or not. (And it worked on some devices while it didn't on others).

    What turned out to be the problem is the property of the characteristics and the writeType.

    Because characteristics can have values set:

    • write without response OR
    • write with response

    In reference to this property you have to set the writeType before writing the actual data to the characteristic.

    You can set the type once you get the Characteristic but before writing to it.

    BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_HEIGHT_INPUT_CHAR);
            if (tChar == null) throw new AssertionError("characteristic null when sync time!");
    
            // use one of them in regards of the Characteristic's property
            tChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
            //tChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
    
    
            tChar.setValue(/*another int*/, BluetoothGattCharacteristic.FORMAT_SINT32, 0);
            gatt.writeCharacteristic(tChar);
    
    0 讨论(0)
  • 2020-12-10 03:23

    In my case, I needed to reuse the active Gatt connection in a new activity but wasn't able to and was constantly disconnecting with error 133. So, I resorted to calling BluetoothGatt.close() before startActivity(), and (re)connect in onStart(). If anyone has a better idea on how to keep the connection, please post.

    0 讨论(0)
  • 2020-12-10 03:25

    For those who may find this post as a result of a status 133 onCharacteristicWrite, I found that we get this 133 result in because the remote device disconnected. I lost a lot of time looking for a problem on the Android side, only to discover later that the problem was on the other side.

    From this I gather that status = 133 seems to be some sort of undocumented generic cause for error.

    0 讨论(0)
  • 2020-12-10 03:28

    Here the error/success status code and meaning

    • GATT_ILLEGAL_PARAMETER 0x0087 (135)
    • GATT_NO_RESOURCES 0x0080 (128)
    • GATT_INTERNAL_ERROR 0x0081 (129)
    • GATT_WRONG_STATE 0x0082 (130)
    • GATT_DB_FULL 0x0083 (131)
    • GATT_BUSY 0x0084 (132)
    • GATT_ERROR 0x0085 (133)
    • GATT_CMD_STARTED 0x0086 (134)
    • GATT_PENDING 0x0088 (136)
    • GATT_AUTH_FAIL 0x0089 (137)
    • GATT_MORE 0x008a (138)
    • GATT_INVALID_CFG 0x008b (139)
    • GATT_SERVICE_STARTED 0x008c (140)
    • GATT_ENCRYPED_MITM GATT_SUCCESS
    • GATT_ENCRYPED_NO_MITM 0x008d (141)
    • GATT_NOT_ENCRYPTED 0x008e (142)
    0 讨论(0)
提交回复
热议问题