简体   繁体   English

在Raspberry Pi中将android-BluetoothChat连接到bluez

[英]Connect android-BluetoothChat to bluez in a Raspberry Pi

I need to connect android-BluetoothChat to a Raspberry Pi B+, preferably headless. 我需要将android-BluetoothChat连接到Raspberry Pi B +,最好是无头。 I installed the scripts here to get the Pi to automatically accept pairing requests, and my Android Tablet (a Walmart ONN) says it is paired with my Pi. 我在这里安装了脚本以使Pi自动接受配对请求,而我的Android平板电脑(Walmart ONN)表示它与我的Pi配对。 The correct MAC address appears in the list from BluetoothAdapter.getDefaultAdapter().getBondedDevices() . BluetoothAdapter.getDefaultAdapter().getBondedDevices()列表中显示正确的MAC地址。

When I run the rfcomm-server.py sample script, it eventually says Accepted connection from ('B4:4B:D6:EE:A2:1C', 1) . 当我运行rfcomm-server.py示例脚本时,它最终表示Accepted connection from ('B4:4B:D6:EE:A2:1C', 1)

But the line mmSocket.connect() in the android-BluetoothChat app fails with the dreaded error java.io.IOException: read failed, socket might closed or timeout, read ret: -1 . 但是android-BluetoothChat应用程序中的行mmSocket.connect()失败并带有可怕的错误java.io.IOException: read failed, socket might closed or timeout, read ret: -1

I still don't get a connection when I invoke the secret method createRfcommSocket() , which StackOverflow recommends to defeat that error. 当我invoke秘密方法createRfcommSocket() ,我仍然没有得到连接,StackOverflow建议用来阻止该错误。

So what should I try next? 那我接下来该尝试什么呢?

Another question: What's the UUID for in the interface? 另一个问题:接口中的UUID是什么? Does the server (the Pi) need to match this UUID? 服务器(Pi)是否需要匹配此UUID? I don't see a reason for the android-BluetoothChat program to generate one randomly. 我没有看到android-BluetoothChat程序随机生成一个的原因。

Here's some log, before anyone has to ask for it: 在有人要求之前,这是一些日志:

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()

解决办法是将MY_UUID_INSECURE更改为00001101-0000-1000-8000-00805F9B34FB, 如何通过蓝牙连接到Android应用程序的Raspberry pi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM