【发布时间】:2019-11-05 16:54:12
【问题描述】:
我需要将android-BluetoothChat 连接到 Raspberry Pi B+,最好是无头的。我安装了脚本here 让 Pi 自动接受配对请求,我的 Android 平板电脑(沃尔玛 ONN)说它与我的 Pi 配对。正确的 MAC 地址出现在来自BluetoothAdapter.getDefaultAdapter().getBondedDevices() 的列表中。
当我运行rfcomm-server.py 示例脚本时,它最终会显示Accepted connection from ('B4:4B:D6:EE:A2:1C', 1)。
但是 android-BluetoothChat 应用程序中的行 mmSocket.connect() 失败并出现可怕的错误 java.io.IOException: read failed, socket might closed or timeout, read ret: -1。
当我 invoke 使用秘密方法 createRfcommSocket() 时仍然没有连接,StackOverflow 建议使用该方法来解决该错误。
那么接下来我应该尝试什么?
另一个问题:界面中的 UUID 是干什么用的?服务器(Pi)是否需要匹配这个 UUID?我没有看到 android-BluetoothChat 程序随机生成一个的原因。
这是一些日志,在任何人都必须要求之前:
D/BluetoothChatService: connect to: B8:27:EB:8D:DC:E7
D/BluetoothChatService: updateUserInterfaceTitle() 1 -> 2
I/BluetoothChatService: BEGIN mConnectThread SocketType:Insecure
W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@d4eebde, this = DecorView@22c41bf[MainActivity]
D/Surface: Surface::disconnect(this=0x7c9bc96000,api=1)
D/Surface: Surface::disconnect(this=0x7c9bc96000,api=1)
W/libEGL: EGLNativeWindowType 0x7c9bc96010 disconnect failed
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@5720682, this = DecorView@7351cf7[DeviceListActivity]
D/View: [Warning] assignParent to null: this = DecorView@7351cf7[DeviceListActivity]
D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@53c843d, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@f3d1432, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@9d50583mSocket: android.net.LocalSocket@db37300 impl:android.net.LocalSocketImpl@4722739 fd:java.io.FileDescriptor@ba4417e, mSocketState: INIT
D/BluetoothChatService: updateUserInterfaceTitle() 2 -> 0
D/BluetoothChatService: start
D/BluetoothSocket: close() this: android.bluetooth.BluetoothSocket@53c843d, channel: -1, mSocketIS: android.net.LocalSocketImpl$SocketInputStream@f3d1432, mSocketOS: android.net.LocalSocketImpl$SocketOutputStream@9d50583mSocket: null, mSocketState: CLOSED
D/BluetoothChatService: updateUserInterfaceTitle() 0 -> 0
D/ViewRootImpl[Toast]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
D/Surface: Surface::connect(this=0x7c8b558000,api=1)
D/Surface: Surface::allocateBuffers(this=0x7c8b558000)
D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/Surface: Surface::disconnect(this=0x7c8b558000,api=1)
D/Surface: Surface::disconnect(this=0x7c8b558000,api=1)
W/libEGL: EGLNativeWindowType 0x7c8b558010 disconnect failed
D/View: [Warning] assignParent to null: this = android.widget.LinearLayout{3348471 V.E...... ......ID 0,0-202,49}
I/d.bluetoothcha: Compiler allocated 5MB to compile void android.view.ViewRootImpl.performTraversals()
【问题讨论】:
标签: android raspberry-pi android-bluetooth bluez pybluez