Android 到蓝牙设备 (WT-11) 通信/连接

发布于 2024-12-07 20:36:14 字数 2980 浏览 1 评论 0原文

因此,我们有一个 Android 应用程序,该应用程序应该与 Bluegiga WT-11 蓝牙模块配对,然后在服务器套接字上侦听来自设备的连接。我们使用 SPP 和 RFCOMM 与“众所周知的”UUID 00001101-0000-1000-8000-00805F9B34FB 进行通信。配对工作正常,但接受服务器套接字上的连接(使用 listenUsingRfcommWithServiceRecord() 创建,然后等待 accept())无法可靠工作。它有时会起作用,但有时会完全停止工作,或者有时会间歇性地工作。

最令人困惑的是,手机似乎正在从设备获取连接,向 LogCat 吐出几行,然后完全忽略连接;设备认为连接失败,并且应用程序永远不会在 accept() 上获得任何连接。

这是当手机(Galaxy S II)获得连接但不执行任何操作时的 LogCat(我现在已经在几部手机上尝试过此操作,如果您需要其他手机的日志或成功的日志),请告诉我连接):

10-05 05:13:14.255: DEBUG/(3341): >>> START GKI_timer_update(), wake_lock_count:3
10-05 05:13:14.255: DEBUG/(3341): >>> RESTARTED GKI_timer_update(): run_cond: 1
10-05 05:13:14.430: WARN/(3341): info:x10
10-05 05:13:14.430: INFO/DTUN_CLNT(3492): dtun-rx signal [DTUN_SIG_DM_LINK_UP] (id 51) len 12
10-05 05:13:14.430: DEBUG/DTUN_HCID4(3492):         dtun_dm_sig_link_up()
10-05 05:13:14.430: INFO/DTUN_HCID4(3492): dtun_dm_sig_link_up: dummy_handle = 375
10-05 05:13:14.435: ERROR/BluetoothEventLoop.cpp(2785): event_filter: Received signal     org.bluez.Device:PropertyChanged from /org/bluez/3492/hci0/dev_00_07_80_4D_B8_E7
10-05 05:13:14.445: INFO//system/bin/btld(3339): send_ctrl_msg: [BTL_IFS CTRL] send     BTLIF_DTUN_SIGNAL_EVT (CTRL) 10 pbytes (hdl 28)
10-05 05:13:14.530: WARN/(3341): amp_find_llcb_by_cid search for CID:0x0040 entry LCID:0x0000 in use 0 CID:0x0001
10-05 05:13:14.910: WARN/(3341): BTA_DM_LINK_DOWN_EVT::bdaddr 00:07:80:4d:b8:e7 reason x13
10-05 05:13:14.910: INFO/DTUN_CLNT(3492): dtun-rx signal [DTUN_SIG_DM_LINK_DOWN] (id 49) len 13
10-05 05:13:14.910: DEBUG/DTUN_HCID4(3492):         dtun_dm_sig_link_down()
10-05 05:13:14.910: INFO/DTUN_HCID4(3492): dtun_dm_sig_link_down device = 0x11c18  handle = 375 reason = 19
10-05 05:13:14.915: ERROR/BluetoothEventLoop.cpp(2785): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/3492/hci0/dev_00_07_80_4D_B8_E7
10-05 05:13:14.915: INFO//system/bin/btld(3339): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 11 pbytes (hdl 28)
10-05 05:13:14.930: INFO/BluetoothHIDService(2785): Received intent Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED (has extras) }, device = 00:07:80:4D:B8:E7
10-05 05:13:14.930: INFO/BluetoothHIDService(2785):     ...ACL disconnected
10-05 05:13:15.865: DEBUG/BatteryService(2785): update start
10-05 05:13:15.870: ERROR/BatteryService(2785): TMU status = 0
10-05 05:13:15.870: DEBUG/BatteryService(2785): updateBattery level:97 scale:100 status:2 health:2 present:true voltage: 4176 temperature: 270 technology: Li-ion AC powered:false USB powered:true icon:17302229
10-05 05:13:15.895: INFO/StatusBarPolicy(2903): BAT. S:2 H:2
10-05 05:13:16.165: DEBUG/(3341): >>> STOP GKI_timer_update(), wake_lock_count:2
10-05 05:13:16.165: DEBUG/(3341): >>> SUSPENDED GKI_timer_update()

@WBAN 你能帮忙解决这个问题吗?我发现你也做过类似的事情。

任何帮助将不胜感激!

谢谢!

So we've got an android application that's supposed to pair with a Bluegiga WT-11 bluetooth module, then listen on a server socket for connections from the device. We're using SPP and RFCOMM for the communication with the "well known" UUID 00001101-0000-1000-8000-00805F9B34FB. The pairing is working ok, but accepting connections on the server socket (created using listenUsingRfcommWithServiceRecord() then waiting on accept()) isn't working reliably. It does work some of the time, but it will stop working all together at times, or just work intermittently at other times.

What's most confusing is that the phone seems to be getting the connection from the device, spitting out a few lines to the LogCat, then ignoring the connection altogether; the device thinks the connection failed and the application never gets any connection on the accept().

Here's the LogCat when the phone (Galaxy S II) gets a connection but doesn't do anything with it (I've tried this on a few phones now, let me know if you need logs from other phones or the log from a successful connection):

10-05 05:13:14.255: DEBUG/(3341): >>> START GKI_timer_update(), wake_lock_count:3
10-05 05:13:14.255: DEBUG/(3341): >>> RESTARTED GKI_timer_update(): run_cond: 1
10-05 05:13:14.430: WARN/(3341): info:x10
10-05 05:13:14.430: INFO/DTUN_CLNT(3492): dtun-rx signal [DTUN_SIG_DM_LINK_UP] (id 51) len 12
10-05 05:13:14.430: DEBUG/DTUN_HCID4(3492):         dtun_dm_sig_link_up()
10-05 05:13:14.430: INFO/DTUN_HCID4(3492): dtun_dm_sig_link_up: dummy_handle = 375
10-05 05:13:14.435: ERROR/BluetoothEventLoop.cpp(2785): event_filter: Received signal     org.bluez.Device:PropertyChanged from /org/bluez/3492/hci0/dev_00_07_80_4D_B8_E7
10-05 05:13:14.445: INFO//system/bin/btld(3339): send_ctrl_msg: [BTL_IFS CTRL] send     BTLIF_DTUN_SIGNAL_EVT (CTRL) 10 pbytes (hdl 28)
10-05 05:13:14.530: WARN/(3341): amp_find_llcb_by_cid search for CID:0x0040 entry LCID:0x0000 in use 0 CID:0x0001
10-05 05:13:14.910: WARN/(3341): BTA_DM_LINK_DOWN_EVT::bdaddr 00:07:80:4d:b8:e7 reason x13
10-05 05:13:14.910: INFO/DTUN_CLNT(3492): dtun-rx signal [DTUN_SIG_DM_LINK_DOWN] (id 49) len 13
10-05 05:13:14.910: DEBUG/DTUN_HCID4(3492):         dtun_dm_sig_link_down()
10-05 05:13:14.910: INFO/DTUN_HCID4(3492): dtun_dm_sig_link_down device = 0x11c18  handle = 375 reason = 19
10-05 05:13:14.915: ERROR/BluetoothEventLoop.cpp(2785): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/3492/hci0/dev_00_07_80_4D_B8_E7
10-05 05:13:14.915: INFO//system/bin/btld(3339): send_ctrl_msg: [BTL_IFS CTRL] send BTLIF_DTUN_SIGNAL_EVT (CTRL) 11 pbytes (hdl 28)
10-05 05:13:14.930: INFO/BluetoothHIDService(2785): Received intent Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED (has extras) }, device = 00:07:80:4D:B8:E7
10-05 05:13:14.930: INFO/BluetoothHIDService(2785):     ...ACL disconnected
10-05 05:13:15.865: DEBUG/BatteryService(2785): update start
10-05 05:13:15.870: ERROR/BatteryService(2785): TMU status = 0
10-05 05:13:15.870: DEBUG/BatteryService(2785): updateBattery level:97 scale:100 status:2 health:2 present:true voltage: 4176 temperature: 270 technology: Li-ion AC powered:false USB powered:true icon:17302229
10-05 05:13:15.895: INFO/StatusBarPolicy(2903): BAT. S:2 H:2
10-05 05:13:16.165: DEBUG/(3341): >>> STOP GKI_timer_update(), wake_lock_count:2
10-05 05:13:16.165: DEBUG/(3341): >>> SUSPENDED GKI_timer_update()

@WBAN Could you help out with this at all? I see you've done something quite similar.

Any help would be greatly appreciated!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文