admin管理员组

文章数量:1391947

Continuously send data 1000 times using the notify method, with an MTU of 512 and each packet being 244 bytes. The onNotificationSent callback is only received after all data has been sent, and there is an issue where status=129 occurs in the notification. At this point, the data has already been sent, making it impossible to stop at the problematic data and perform the corresponding handling. The current approach is to send one data packet using notifyCharacteristicChanged, then wait for the onNotificationSent callback to confirm success before sending the next packet. I would like to ask if there is a better approach to achieve the fastest transmission speed.

// Send 1000 times.

charForIndicate?.let {
    for (device in subscribedDevices) {
        for (i in 0 until 1000) {
            it.value = byteArray
            result = gattServer?.notifyCharacteristicChanged(device, it, false)
        }
    }
}

// BluetoothGattServerCallback.

override fun onNotificationSent(device: BluetoothDevice, status: Int) {
    handler.post {
        Log.e("CameraDirecrt", "onNotificationSent status=$status")
    }
}

The error status=129 occurs when sending 1000 times.

The approach is modified to send one data packet using notifyCharacteristicChanged, and then wait for the onNotificationSent callback to confirm success before sending the next packet.

本文标签: