Knowing RFComm port number to connect to we are fully set for our final step – to establish RFComm communication channel. Before we can send RFComm specific commands we need to establish L2CAP connection to RFComm the same way as it has been already described in ‘Establishing connection to SDP’. The only difference is that this time we need to use RFComm PSM (0x03) rather than SDP PSM. Let’s not focus our attention on L2CAP as it is now a technicality of no interest and shift our attention to RFComm specifics.
Make the same preparations and run two consoles with logging hcpdump applications and it was described in this post. Let’s analyze packet exchange immediately after establishing connection to RFComm. Here is what the first console would typically report:
< ACL data: handle 43 flags 0x02 dlen 8 L2CAP(d): cid 0x0041 len 4 [psm 3] RFCOMM(s): SABM: cr 1 dlci 0 pf 1 ilen 0 fcs 0x1c //1-st SABM command > ACL data: handle 43 flags 0x02 dlen 8 L2CAP(d): cid 0x0041 len 4 [psm 3] RFCOMM(s): UA: cr 1 dlci 0 pf 1 ilen 0 fcs 0xd7 //UA response < ACL data: handle 43 flags 0x02 dlen 18 L2CAP(d): cid 0x0041 len 14 [psm 3] RFCOMM(s): PN CMD: cr 1 dlci 0 pf 0 ilen 10 fcs 0x70 mcc_len 8 //PM (paramater negotiation) request dlci 32 frame_type 0 credit_flow 15 pri 7 ack_timer 0 frame_size 55 max_retrans 0 credits 7 > ACL data: handle 43 flags 0x02 dlen 18 L2CAP(d): cid 0x0041 len 14 [psm 3] RFCOMM(s): PN RSP: cr 0 dlci 0 pf 0 ilen 10 fcs 0xaa mcc_len 8 //PM (parameter negotiation) response dlci 32 frame_type 0 credit_flow 14 pri 0 ack_timer 0 frame_size 55 max_retrans 0 credits 7 < ACL data: handle 43 flags 0x02 dlen 8 L2CAP(d): cid 0x0041 len 4 [psm 3] RFCOMM(s): SABM: cr 1 dlci 32 pf 1 ilen 0 fcs 0xca //2-nd SAMB command > ACL data: handle 43 flags 0x02 dlen 8 L2CAP(d): cid 0x0041 len 4 [psm 3] RFCOMM(s): UA: cr 1 dlci 32 pf 1 ilen 0 fcs 0x1 //UA response < ACL data: handle 43 flags 0x02 dlen 12 L2CAP(d): cid 0x0041 len 8 [psm 3] RFCOMM(s): MSC CMD: cr 1 dlci 0 pf 0 ilen 4 fcs 0x70 mcc_len 2 //MSC (modem status) command dlci 32 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0 > ACL data: handle 43 flags 0x02 dlen 12 L2CAP(d): cid 0x0041 len 8 [psm 3] RFCOMM(s): MSC CMD: cr 0 dlci 0 pf 0 ilen 4 fcs 0xaa mcc_len 2 //MSC (modem status) command dlci 32 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0 < ACL data: handle 43 flags 0x02 dlen 12 L2CAP(d): cid 0x0041 len 8 [psm 3] RFCOMM(s): MSC RSP: cr 1 dlci 0 pf 0 ilen 4 fcs 0x70 mcc_len 2 //MSC (modem status) response dlci 32 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0 > ACL data: handle 43 flags 0x02 dlen 12 L2CAP(d): cid 0x0041 len 8 [psm 3] RFCOMM(s): MSC RSP: cr 0 dlci 0 pf 0 ilen 4 fcs 0xaa mcc_len 2 //MSC (mode status) response dlci 32 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0 < ACL data: handle 43 flags 0x02 dlen 9 L2CAP(d): cid 0x0041 len 5 [psm 3] RFCOMM(d): UIH: cr 1 dlci 32 pf 1 ilen 0 fcs 0xc4 credits 33 //Command with credit
Let’s have a look at the same exchange in raw representation logged by the second console and try to decode it:
< 0000: 02 2a 20 08 00 04 00 41 00 03 3f 01 1c .* ....A..?.. //1-st SABM on channel 0 (byte @ 0x9 == 0x3) > 0000: 02 2a 20 08 00 04 00 41 00 03 73 01 d7 .* ....A..s.. //UA response < 0000: 02 2a 20 12 00 0e 00 41 00 03 ef 15 83 11 20 f0 .* ....A...... . //PM (paramater negotiation) request 0010: 07 00 37 00 00 07 70 ..7...p > 0000: 02 2a 20 12 00 0e 00 41 00 01 ef 15 81 11 20 e0 .* ....A...... . //PM (parameter negotiation) response 0010: 00 00 37 00 00 07 aa ..7.... < 0000: 02 2a 20 08 00 04 00 41 00 83 3f 01 ca .* ....A..?.. //2-nd SABM on channel 0x10 (byte @ 0x9 == 0x83, channel number << 3 = 0x80) > 0000: 02 2a 20 08 00 04 00 41 00 83 73 01 01 .* ....A..s.. //UA response < 0000: 02 2a 20 0c 00 08 00 41 00 03 ef 09 e3 05 83 8d .* ....A........ //MSC (modem status) command 0010: 70 p > 0000: 02 2a 20 0c 00 08 00 41 00 01 ef 09 e3 05 83 8d .* ....A........ //MSC (modem status) command 0010: aa . < 0000: 02 2a 20 0c 00 08 00 41 00 03 ef 09 e1 05 83 8d .* ....A........ //MSC (modem status) response 0010: 70 p > 0000: 02 2a 20 0c 00 08 00 41 00 01 ef 09 e1 05 83 8d .* ....A........ //MSC (modem status) response 0010: aa . < 0000: 02 2a 20 09 00 05 00 41 00 83 ff 01 21 c4 .* ....A....!. //Command with credit on channel 0x10 ...and... rock'n'roll!
Time to put everything together. Get source code from Download section below, update your installation of USB Host 2.0 library on your machine, run the provided sketch making sure that ELM327 is powered and within range of your Luminardo board. You should see something similar to the output provided below. Note, that very last reply >LM327 v1.5
is transmitted by ELM327 which means that we have established SPP communication channel! The only remaining part now is to put logic which communicates with ELM327 and renders received values on VFD panel.
Luminardo USB Host Bluetooth SPP Test SPP Bluetooth Library Started Enabling VBus... enabled Bluetooth Dongle Initialized HCI Reset complete Write class of device Local Bluetooth Address: 00:19:0E:12:65:6A The name is set to: Luminardo Pairing to 'Other' device with predefined address Device: 40:22:11:00:69:58 has been found Connecting to 'Other' device... Connected to 'Other' device Received Key Request Bluetooth pin is set too: 1234 Pairing successful with 'Other' device SDP Connection Request Sent L2CAP Connection Response SDP Connection Response SDP Configuration Request Received SDP Configuration Response Sent SDP Configuration Request Sent SDP Configuration Response Received SDP Successfully Configured SDP Service Search Attribute Request 1 Sent Channel will be in the next packet SDP Service Search Attribute Request 2 Sent Channel found in second packet: 16 RFComm Connection Request Sent L2CAP Connection Response RFComm Connection Response RFComm Configuration Request Received RFComm Configuration Response Sent RFComm Configuration Request Sent RFComm Configuration Response Received RFComm Successfully Configured RFComm SABM Sent Received UA RFComm Packet on channel: 00 Sent UAH RFComm Cmd BT_RFCOMM_PN_CMD (Parameter Negotiation Request) on channel: 00 Received UIH RFComm Packet on channel: 00 - BT_RFCOMM_PN_RSP (Parameter Negotiation Response) RFComm 2-nd SABM Sent Received UA RFComm Packet on channel: 10 Send UIH RFComm Cmd BT_RFCOMM_MSC_CMD (Modem Status Command) Received UIH RFComm Packet on channel: 00 - BT_RFCOMM_MSC_CMD (Modem Status Cmd) Send UIH RFComm Cmd BT_RFCOMM_MSC_RSP (Modem Status Response) Received UIH RFComm Packet on channel: 00 - BT_RFCOMM_MSC_RSP (Modem Status Response) RFComm Cmd with Credit Sent Serial Bluetooth connected >LM327 v1.5
Now the implemented functionality allows to establish SPP communication between two Arduino boards equipped with USB Host shields. It is also quite remarkable that this particular Bluetooth dongle is not functional under WinXP because it comes with Win8 driver only yet our hardware happily communicates with the dongle!
Downloads:
1. USB Host 2.0 For Arduino – Bluetooth SPPi addon;
2. UPDATE 2014.09.28: Full snapshot of USB Host 2.0 For Arduino with Bluetooth SPPi addon;
Loving the work put into this as it is exactly what I was looking for.
Unfortunately the examples do not seem to compile correctly due to an error in Usb.cpp :
Arduino: 1.5.7 (Windows 8), Board: “Arduino Uno”
Build options changed, rebuilding all
C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_20\Usb.cpp: In member function ‘uint8_t USB::Configuring(uint8_t, uint8_t, bool)’:
C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_20\Usb.cpp:714:47: error: ‘class USBDeviceConfig’ has no member named ‘DEVSUBCLASSOK’
if(devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) {
^
C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_20\Usb.cpp:730:47: error: ‘class USBDeviceConfig’ has no member named ‘DEVSUBCLASSOK’
if(devConfig[devConfigIndex]->DEVSUBCLASSOK(subklass) && (devConfig[devConfigIndex]->VIDPIDOK(vid, pid) || devConfig[devConfigIndex]->DEVCLASSOK(klass))) continue; // If this is true it means it must have returned USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED above
^
This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
Thank you for the feedback, I’ll have a look at it today-tomorrow.
No probs Dmitry, thanks for the speedy reply.
Just to add a bit more info to make chasing the bug easier. I’m compiling on Windows 8.1 with the 1.5.7 build of the Arduino IDE. I have tried Arduino 1.0.6 which generates the exact same error.
I’m using the latest USB Host Shield code from : https://github.com/felis/USB_Host_Shield_2.0
Using the above I simply overwrote the necessary files in the USB library and then attempted to compile the example.
Solved !
In your replacement “UsbCore.h” , after line 154 it’s missing the following :
virtual boolean DEVSUBCLASSOK(uint8_t subklass) {
return true;
}
Add that and comment out “#include ” in the example (so it’ll compile on standard Arduinos) and it then compiles fine. Heres a link to it in my Dropbox if you want a pre-edited file :
https://dl.dropboxusercontent.com/u/45418759/UsbCore.h
Now I need to figure out why it now stops at “SDP Connection Response” with my setup 🙂
Hi,
just tried to grab the latest USB_Host_Shield_2.0 and apply my addon – and immediately got the same error.
The thing with my addon is that is has never been made part of official USB Host Library. At some point I contacted USB Host Lib developers, they were happy to merge my code but then they discovered that it didn’t work with Macbook. Originally I tested my addon with ELM327 and I warned them that there could be still some peculiarities with some platforms. They didn’t want to find out why it was refusing to work with Macbooks and honestly speaking at that time I wasn’t keen to make someone else’s library perfect so we never merged to final code.
As a first step I can suggest you to try a snapshot of the library which works for me (in essence, it is April’s revision of USB Host Lib plus my addon) http://magictale.com/wp-content/uploads/2014/09/USB_Host_Shield_2__SPPi_Full__2014_04_22.zip
Can I also suggest to continue discussion at http://forum.magictale.com/viewtopic.php?f=1&t=2611#p2579 as it would be a bit more convenient? (You don’t have to register again, your account should work equally fine for both blog and forum).
Thank you.