ESP32 UART HCI RFCOMM
Posted: Thu Aug 15, 2019 3:09 am
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?
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?