I'm trying to use the ESP32 as a bluetooth coprocessor for a raspberry pi compute module using HCI. It seemed like everything was working, but then hit a last minute snag that I can't find a solution for. The device is able to successfully pair with the Android cell phone that I'm trying to use as the bluetooth master device. However, trying to open an RFCOMM socket never seems to succeed.
I receive the following error on the host (Android phone):
W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
W/System.err: at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:698)
W/System.err: at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:710)
W/System.err: at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:387)
Looking the internals of the android socket class, it appears to be hitting this error trying to read the channel from the rfcomm input stream, which is the first attempt to read data off the socket after establishing a connection.
On the raspberry pi I setup tracing using btmon and I see the following output, it appears to hang on this line, then fail after several seconds. This part in the btmon output seems to coincide with the failure:
> ACL Data RX: Handle 128 flags 0x02 dlen 14 [hci0] 75.711662
L2CAP: Command Reject (0x01) ident 5 len 6
Reason: Invalid CID in request (0x0002)
Destination CID: 0
Source CID: 0
I've tried lot of things and have been stumped as to why I can't open an RFCOMM connection. Does anybody have any suggestions?
ESP32 UART HCI RFCOMM
Re: ESP32 UART HCI RFCOMM
Update: I tried using the Android hack for connecting directly using a channel ID rather than a UUID (essentially skipping the SDP lookup), and this resulted in the same error - suggesting that the problem is with the actual connection rather than the SDP lookup.
After trying a few more things I switched gears to trying to use the phone as the bluetooth slave instead of the device. This is not my preferred approach. Here I saw more success, but still things aren't working as expected:
discover_devices from pybluez doesn't report any devices, although the phone and bluetoothctl both show the devices as paired. However, if I hardcode in the device address I see in pybluez, I am actually able to connect. Not sure what to make of this problem.
Some thoughts: does the ESP32 support working as a bluetooth slave? Is there anything additional I should do beyond the code that's in the controller_hci_uart example to enable slave RFCOMM capabilities on the ESP32, or should this just work?
After trying a few more things I switched gears to trying to use the phone as the bluetooth slave instead of the device. This is not my preferred approach. Here I saw more success, but still things aren't working as expected:
discover_devices from pybluez doesn't report any devices, although the phone and bluetoothctl both show the devices as paired. However, if I hardcode in the device address I see in pybluez, I am actually able to connect. Not sure what to make of this problem.
Some thoughts: does the ESP32 support working as a bluetooth slave? Is there anything additional I should do beyond the code that's in the controller_hci_uart example to enable slave RFCOMM capabilities on the ESP32, or should this just work?
Who is online
Users browsing this forum: Bing [Bot] and 178 guests