【问题标题】:Problem with file transfer over BLE on AndroidAndroid上通过BLE传输文件的问题
【发布时间】:2020-02-07 00:19:41
【问题描述】:

我致力于通过 BLE 将文件从智能手机传输到外围设备。

通过 BLE 发送数据很慢(数据传输是通过覆盖一个 20 字节长的字符来实现的)。速度慢不是问题,因为文件的大小也非常小(最多 1MB)。

在琐碎的测试中,一切正常。只要我尝试在循环中自动运行文件传输(例如,出于测试目的让它整夜运行),在具有蓝牙标准 4.2 的设备上,Android 会在短时间内向 Logcat 发送以下内容

01-24 13:44:08.411  1002  2449 10116 D vendor.qti.bluetooth@1.0-uart_controller: ReportSocFailure
01-24 13:44:08.411  1002  2449 10116 D vendor.qti.bluetooth@1.0-uart_controller: ReportSocFailure send soc failure
01-24 13:44:08.411  1002  2449 10116 E vendor.qti.bluetooth@1.0-uart_controller: Error reading data from uart

在向该输出发送垃圾邮件数秒后,以下输出被写入 Logcat,表示蓝牙正在停止/重新启动

1-24 13:44:08.428  1002  2449  2449 W vendor.qti.bluetooth@1.0-async_fd_watcher: StopThread: stopped the work thread
01-24 13:44:08.428  1002  2449  2449 D vendor.qti.bluetooth@1.0-uart_transport: userial clock off

01-24 13:44:38.527  1002  2449  2449 I vendor.qti.bluetooth@1.0-uart_transport: DeInitTransport: Transport is being closed!
01-24 13:44:38.528  1002  2449  2449 D vendor.qti.bluetooth@1.0-power_manager: SetPower: enable: 0
01-24 13:44:38.529  1002  2449  2449 D vendor.qti.bluetooth@1.0-power_manager: GetRfkillFd: rfkill_fd: 9
01-24 13:44:38.529  1002  2449  2449 D vendor.qti.bluetooth@1.0-power_manager: ControlRfkill: rfkill_fd: 9, enable: 0
01-24 13:44:38.637  1002  2449  2449 W vendor.qti.bluetooth@1.0-data_handler: controller Cleanup done
01-24 13:44:38.638  1002  2449  2449 I vendor.qti.bluetooth@1.0-data_handler: DataHandler:: joined Init thread 
01-24 13:44:38.638  1002  2449  2449 E vendor.qti.bluetooth@1.0-wake_lock: Release wake lock not initialized/acquired
01-24 13:44:38.638  1002  2449  2449 D vendor.qti.bluetooth@1.0-wake_lock: CleanUp wakelock is destroyed 
01-24 13:44:38.638  1002  2449  2449 W vendor.qti.bluetooth@1.0-bluetooth_hci: BluetoothHci::close, finish cleanup


01-24 13:44:38.713 u0_a3  3430  3430 D BluetoothSap: Proxy object disconnected
01-24 13:44:38.715  1000 26585 26585 D A2dpProfile: Bluetooth service disconnected
01-24 13:44:38.716  1000 26585 26585 D BluetoothSap: Proxy object disconnected
01-24 13:44:38.718  1000 26585 26585 D SapProfile: Bluetooth service disconnected
01-24 13:44:38.719  1000 26585 26585 D BluetoothInputDevice: Proxy object disconnected
01-24 13:44:38.719 10137 28340 28340 D BluetoothInputDevice: Proxy object disconnected

在这些事件之后,用于写入数据的服务重新启动,我的猜测是因为设备上的蓝牙模块也重新启动。

在蓝牙标准 4.0 的设备上一切正常,我可以让持续的文件传输运行一天,不会发生崩溃。

您对为什么会发生这种情况有任何想法或建议吗?为了与蓝牙适配器交互我使用库 RxBle

https://github.com/Polidea/RxAndroidBle

谢谢。

【问题讨论】:

  • 我仍然想弄清楚您为什么要通过 BLE 传输实际文件。
  • 文件传输的内容是小的二进制文件(一个最大250kB)。这些文件包含设备的固件更新。
  • 嗯,它崩溃的事实显然是您特定 Android 设备中的一个错误。为什么不向制造商投诉?

标签: android bluetooth-lowenergy


【解决方案1】:

从 Android api 级别 21 起,您可以从要发送到的外围设备请求更大的 MTU 大小,如上所述 here。这将允许您发送最多 517 字节的数据包,这使您的传输比发送 20 字节的 ocket 相对更快。但是,只有当您的 ble 设备支持更大的 MTU 大小时,这才有可能。如果您打算进行固件更新,我建议您的外围设备和智能手机应用程序都应使用适当的固件更新协议,这也可能取决于外围设备上使用的蓝牙芯片的制造商。希望这会有所帮助。

【讨论】:

  • 您好,首先感谢您抽出宝贵时间回答我的问题。我会看看一个合适的固件更新协议。
【解决方案2】:

仅供参考 - 我在 BLE Kotlin Coroutines 库的问题跟踪系统中发现了与我的问题类似的问题 - 我的错误消息与此处报告的错误消息完全匹配:

Problem with file transfer over BLE on Android

在给定问题的描述中,指出该问题发生在设备三星 Galaxy A5 上,这正是我使用的设备。

所以我得出的结论是这个问题可能与这个特定的设备有关,只要我可以在多部不同的手机上连续运行固件更新而不会出现问题。我没有进一步调查。

我对此的解决方案是 - 当应用更新失败时(BT 错误,电池耗尽,设备将超出 BT 范围),一切都将被重置,更新将再次尝试运行。您只是无法预测不同设备是否/如何/何时会出现异常 - 解决方案不是尝试修补所有可能发生的错误,而是让系统能够从错误中恢复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    • 1970-01-01
    • 2013-01-17
    • 2021-12-15
    相关资源
    最近更新 更多