2

Environment: Bluez 5.14, Linux 3.1, USB Plugable BLE radio, TI BLE keyfob (CC2541 dev kit) Linux Device <---hci----> USB BLE Radio

We enabled key press events on TI keyfob using gatttool and started to listen for events

gatttool -b [hardware ID] --char-write-req -a [handle] -n [value] --listen 
(gatttool -b 90:59:AF:09:E1:5D --char-write-req -a 0x0048 -n 0100 --listen)

Pressing buttons on the keyfob and see these events

Notification handle = 0x0047 value: 02 
Notification handle = 0x0047 value: 00 
Notification handle = 0x0047 value: 02

Hence we can receive the key press events from the Keyfob through the Bluez stack

Objective:

We need to catch the GATT Disconnect Event i.e. When we remove the battery from the keyfob sooner or later the GATT connection is broken. We would like to receive a disconnect event from Bluez stack. Bluez has this capability since Android supports GATT disconnect event which is built over Bluez.

Question:

How do we receive the GATT Disconnect event using Bluez command line hcitool/gatttool or Bluez API.

AjayKumarBasuthkar
  • 2,885
  • 2
  • 23
  • 27
SC-SL
  • 377
  • 3
  • 19
  • Simply put - How do we find that the GATT or Bluetooth connection is broken. We need this for many reasons - to cleanup resources, to restart the lescan etc. – SC-SL Feb 15 '14 at 12:16

1 Answers1

1

Watch for G_IO_HUP and shutdown gracefully.

chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
                opt_psm, opt_mtu, connect_cb, &gerr);
if (chan == NULL) {
    log_printf(LOG_LEVEL_ERROR,"%s: chan is NULL\n",__func__);
    log_printf(LOG_LEVEL_ERROR,"%s\n", gerr->message);
    g_error_free(gerr);
    g_main_loop_quit(event_loop);
} else {
    log_printf(LOG_LEVEL_INFO,"Connected to %s\n",opt_dst);
    g_io_add_watch(chan, G_IO_HUP, channel_watcher, NULL);
}
bill davis
  • 323
  • 2
  • 9
  • This works like a charm, however since detection is at GATT layer a disconnect because of battery removal take a long time to detect. A detection at BLE layer would be ideal. – SC-SL May 02 '14 at 08:42
  • It's very nice to know that it's possible at all. But why "gatttool --listen" doesn't notice disconnect and just hangs there forever? Is it just notorious bluez bugginess and user-unfriendliness? Just in case, bluez 4.101 (as shipped with Ubuntu 14.04LTS). – pfalcon Nov 30 '15 at 14:24