how to disconnect? (rfcomm)

653 views
Skip to first unread message

xius

unread,
Apr 29, 2012, 12:59:34 PM4/29/12
to btstack-dev
Hi all,

I'm unable to find out how to actually disconnect from a device with
which I do have a rfcomm connection. I'm using provided
BTstackManager.
My code is as follows:

bt_send_cmd(&rfcomm_disconnect, rfcommChannelID, 0);

The "rfcommChannelID" is from:

- (void)btstackManager:(BTstackManager*)manager
handlePacketWithType:(uint8_t)packet_type
forChannel:(uint16_t)channel
andData:(uint8_t *)packet
withLen:(uint16_t)size
{
bd_addr_t event_addr;
switch (packet_type) {
...
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
rfcommChannelID = READ_BT_16(packet, 12);
break;
...
}
}

Is there something wrong? Device stil seems to be connected (its LED
indicates it), although no data are incoming.
Thank you!

Matthias Ringwald

unread,
Apr 29, 2012, 2:53:50 PM4/29/12
to btsta...@googlegroups.com
Hi Xius

your code below looks correct. Can you send us(me) a packet log?
See http://btstack.uservoice.com/knowledgebase/articles/69548-how-to-get-btstack-communication-log

Best
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To post to this group, send email to btsta...@googlegroups.com.
> To unsubscribe from this group, send email to btstack-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/btstack-dev?hl=en.
>

xius

unread,
Apr 30, 2012, 3:47:16 AM4/30/12
to btstack-dev
Here:
http://dl.dropbox.com/u/5552845/hci_dump.pklg

On Apr 29, 8:53 pm, Matthias Ringwald <matthias.ringw...@gmail.com>
wrote:
> Hi Xius
>
> your code below looks correct. Can you send us(me) a packet log?
> Seehttp://btstack.uservoice.com/knowledgebase/articles/69548-how-to-get-...

Matthias Ringwald

unread,
Apr 30, 2012, 4:52:04 AM4/30/12
to btsta...@googlegroups.com
Hi

In the packet log, the rfcomm cid is 0x0011

In the rfcomm disconnect, the rfcomm cid is 0x0000
Please double check your code and printf the rfcomm cid value

Looking at the logs, I guess it would be worthwhile do fully dump all custom BTStack commands and events as NOTEs too. Would be even quicker for debugging.

Best
Matthias

Screen shot 2012-04-30 at 10.37.47 AM.png
Screen shot 2012-04-30 at 10.38.00 AM.png

Jens David

unread,
Apr 30, 2012, 5:31:58 AM4/30/12
to btsta...@googlegroups.com
Yes, indeed I think that would help a lot I think!
Drawback of course is that the string constants would bloat the executable size (only a problem for small MCUs)...

-j
> <Screen shot 2012-04-30 at 10.37.47 AM.png><Screen shot 2012-04-30 at 10.38.00 AM.png>--
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To post to this group, send email to btsta...@googlegroups.com.
> To unsubscribe from this group, send email to btstack-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/btstack-dev?hl=en.
>

--
Jens David, DG1KJD
jens....@jens-david-consulting.com
http://www.jens-david-consulting.com



xius

unread,
Apr 30, 2012, 7:04:53 AM4/30/12
to btstack-dev
Hi,

thank you! Shame on me as the bug was really silly (copy'n'paste
category, eh). 0x0000 value is the default, getting the actual one
never occurred. Instead of:

switch (packet_type) {
case HCI_EVENT_PACKET:
switch (packet[0]) {
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
rfcommChannelID = READ_BT_16(packet, 12);
break;
...
}
}
}

I was doing:

switch (packet_type) {
case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
rfcommChannelID = READ_BT_16(packet, 12);
break;
...
}

So, thank you again for your time, I was sure I'm doing wrong
something essential...
Also, I agree adding notes, that would be really helpful! :)

On Apr 30, 10:52 am, Matthias Ringwald <matthias.ringw...@gmail.com>
wrote:
>  Screen shot 2012-04-30 at 10.37.47 AM.png
> 22KViewDownload
>
>  Screen shot 2012-04-30 at 10.38.00 AM.png
> 17KViewDownload
>
>
>
> On Apr 30, 2012, at 9:47 AM, xius wrote:
>
>
>
>
>
>
>

xius

unread,
Apr 30, 2012, 7:16:22 AM4/30/12
to btstack-dev
Well, that was premature. :) Now, I'm definitely working with the
right channel id, however the device still believes it's connected.
When I run it - app crashes together with bt.
Here are my current log:
http://dl.dropbox.com/u/5552845/hci_dump.pklg

Is there anything I should do to disconnect?

Matthias Ringwald

unread,
Apr 30, 2012, 5:12:45 PM4/30/12
to btstack-dev
Hi

Some comments on your log file:
* the Inquiry is never stopped. You should stop inquiry after you found the device to connect to (it takes a lot of energy and degrades performance of data transmissions).
* you're using the correct rfomm channel ID, but BTdaemon doesn't start shutting down the RFCOMM channel right away. That's not correct, I have to look into that (somehow).
* You're app seems to crash. Can you find out why it crashes?

Best
Matthias
Reply all
Reply to author
Forward
0 new messages