语言

Menu
Sites
Language
Connection via Bluetooth LE

Hi there. I'm working on application where Gear connects to iPhone via Bluetooth LE. The next roles is selected:
Gear (Central) and iPhone (Peripheral). I have some issue (strange for me) when Gear is connecting to iPhone.

Let me describe what I do step by step. I'll put only Tizen calls without error processing and my internal logic.

  1. Initialization
    bt_initialize();
    bt_adapter_get_state(&state);
    if (state == BT_ADAPTER_DISABLED)
    {
      return error;
    }
  2. Start scanning
    bt_gatt_set_connection_state_changed_cb(
                    __bt_gatt_connection_state_changed_cb, NULL); 
    
    bt_adapter_le_start_scan(__bt_adapter_le_scan_result_cb, NULL);
    I see in system logs that service with requested UUID is found.
    01-10 17:25:35.019+0200 I/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: bluetooth_start_le_discovery(110) >  ### Start LE scan 
    01-10 17:25:35.019+0200 I/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: bluetooth_start_le_discovery(112) >  Sync Request => type=BT_BLUEZ_SERVICE, fn=BT_START_LE_DISCOVERY(0x11) 
    01-10 17:25:35.039+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(163) > Method[service_request] Object Path[/org/projectx/bt_service] Interface Name[org.projectx.bt]
    01-10 17:25:35.039+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(236) > Service type = 0, fn = BT_START_LE_DISCOVERY (0x11)
    01-10 17:25:35.039+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-adapter-le.c: _bt_set_scan_parameters(797) > Set scan parameters
    01-10 17:25:35.039+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-adapter-le.c: _bt_start_le_scan(1338) > Start LE Full Scan
    01-10 17:25:35.049+0200 D/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: _bt_set_le_scan_status(92) > set LE scan mode : 1
    01-10 17:25:35.579+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_adapter_property_changed_event(617) > Property LEDiscovering
    01-10 17:25:35.579+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_adapter_property_changed_event(659) > LEDiscovering 1
    # 9148 is a PID of my application, I stripped logs to remove information about my app
    # This is log from my scan_result_cb
    01-10 17:25:35.979+0200 ( 9148):  __bt_adapter_le_scan_result_cb:76: Service is scanning
    01-10 17:25:35.979+0200 ( 9148):  [__bt_adapter_le_scan_result_cb, line = 104] Remote address = 6F:0B:DA:7A:B4:D5
    01-10 17:25:35.979+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(413) > event_type [3], event [14]
    01-10 17:25:35.979+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(454) >  Signal : LEDeviceFound 
    
    01-10 17:25:35.989+0200 ( 9148):  __bt_adapter_le_scan_result_cb:125: UUID 0 = 00001101-0000-1000-8000-00805F9B3400
    01-10 17:25:35.989+0200 ( 9148):  __bt_adapter_le_scan_result_cb:130: Found desired UUID 00001101-0000-1000-8000-00805F9B3400
    
    01-10 17:25:36.009+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(413) > event_type [3], event [14]
    01-10 17:25:36.009+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(454) >  Signal : LEDeviceFound 
    01-10 17:25:36.039+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_device_property_changed_event(904) > +
    01-10 17:25:36.039+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_device_property_changed_event(916) > Property UUIDs
    01-10 17:25:36.039+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_device_property_changed_event(1223) > -
  3. Wait until device with requested servise found or timeout expired. After that stop scanning.
    bt_adapter_le_stop_scan();
    System logs.
    # 6F:0B:DA:7A:B4:XX is a hidden iPhone bluetooth address
    01-10 17:25:36.079+0200 I/BLUETOOTH_FRWK_API( 2498): bt-gatt-client.c: _bluetooth_gatt_check_service_change_watcher_address(137) > service_monitor_list [6F:0B:DA:7A:B4:XX] - Input [6F:0B:DA:7A:B4:XX]
    01-10 17:25:36.079+0200 I/BLUETOOTH_FRWK_API( 2498): bt-event-handler.c: __bt_manager_event_filter(2738) >  ### GATT Service added [/org/bluez/hci0/dev_6F_0B_DA_7A_B4_D5/service0039] [6F:0B:DA:7A:B4:XX]
    01-10 17:25:36.079+0200 I/BLUETOOTH_FRWK_API( 2522): bt-telephony.c: __bt_telephony_adapter_filter(2295) > Adapter Path = [/org/bluez/hci0/dev_6F_0B_DA_7A_B4_D5/service0039/char003a/desc003d]
    01-10 17:25:36.089+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_gatt_char_property_changed_event(1519) > Property Flags
    01-10 17:25:36.089+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(413) > event_type [3], event [14]
    01-10 17:25:36.089+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(454) >  Signal : LEDeviceFound 
    01-10 17:25:36.139+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(413) > event_type [3], event [14]
    01-10 17:25:36.139+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(454) >  Signal : LEDeviceFound 
    01-10 17:25:36.149+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(413) > event_type [3], event [14]
    01-10 17:25:36.149+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event_to_dest(454) >  Signal : LEDeviceFound 
    01-10 17:25:36.159+0200 I/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: bluetooth_stop_le_discovery(131) >  ### Stop LE scan 
    01-10 17:25:36.159+0200 I/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: bluetooth_stop_le_discovery(133) >  Sync Request => type=BT_BLUEZ_SERVICE, fn=BT_STOP_LE_DISCOVERY(0x12) 
    01-10 17:25:36.159+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(163) > Method[service_request] Object Path[/org/projectx/bt_service] Interface Name[org.projectx.bt]
    01-10 17:25:36.159+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(236) > Service type = 0, fn = BT_STOP_LE_DISCOVERY (0x12)
    01-10 17:25:36.159+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-adapter-le.c: _bt_stop_le_scan(1433) > Just stop LE scan
    01-10 17:25:36.179+0200 D/BLUETOOTH_FRWK_API( 9148): bt-adapter-le.c: _bt_set_le_scan_status(92) > set LE scan mode : 0
    # This is my custom Bluetooth Service. UUID is correct. It has 1 characteristic, so logs are correct.
    01-10 17:25:36.179+0200 I/BLUETOOTH_FRWK_API( 2498): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 00001101-0000-1000-8000-00805f9b3400 [Unknown]
    01-10 17:25:36.179+0200 D/BLUETOOTH_FRWK_API( 2498): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    
  4. The next step is initiate connection.
    bt_gatt_connect(iphone_address, true);
    
    bt_gatt_client_h client_handle = NULL;
    bt_gatt_client_create(iphone_address, &client_handle);
    After that I can see next logs.
    01-10 17:25:36.179+0200 W/WECONN  ( 2498): <__on_change_gatt_client:366> {
    01-10 17:25:36.179+0200 W/WECONN  ( 2498): <__on_change_gatt_client:370> chage_type : 0, service_uuid : 00001101-0000-1000-8000-00805f9b3400
    01-10 17:25:36.179+0200 D/WECONN  ( 2498): <__on_change_gatt_client:846> remote_address : B4:D5
    01-10 17:25:36.179+0200 W/WECONN  ( 2498): <__is_device_matched_to:2565> le : B4:D5, br_edr : 99:42, identifier : B4:D5
    01-10 17:25:36.179+0200 D/WECONN  ( 2498): <wc_bt_get_gatt_client_service:2003> ##
    
    # I think this is a root cause why connection is not established. I don't know what is service with UUID 9a3f68e0-86ce-11e5-a309-0002a5d5c51b.
    # I don't have such UUID in my code at all. Error -61 means BT_ERROR_NO_DATA.
    01-10 17:25:36.179+0200 E/WECONN  ( 2498): <wc_bt_get_gatt_client_service:2007> ret : -61
    01-10 17:25:36.179+0200 E/WECONN  ( 2498): <__create_gatt_handle_into:1169> Fail wc_bt_get_gatt_client_service[9a3f68e0-86ce-11e5-a309-0002a5d5c51b]/[-61]
    01-10 17:25:36.189+0200 W/WECONN  ( 2498): <__on_change_gatt_client:374> }
    
    01-10 17:25:36.189+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_adapter_property_changed_event(617) > Property LEDiscovering
    01-10 17:25:36.189+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_adapter_property_changed_event(659) > LEDiscovering 0
    01-10 17:25:36.189+0200 E/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-receiver.c: __bt_adapter_property_changed_event(684) > Dbus Error GDBus.Error:org.bluez.Error.Failed: No discovery started
    01-10 17:25:36.199+0200 D/BLUETOOTH_FRWK_API( 9148): bt-common.c: _bt_check_privilege(1884) > Sync Request => type=service_type, fn=service_function(0x159)
    01-10 17:25:36.199+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(163) > Method[service_request] Object Path[/org/projectx/bt_service] Interface Name[org.projectx.bt]
    01-10 17:25:36.199+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(236) > Service type = 4, fn = BT_CONNECT_LE (0x159)
    01-10 17:25:36.199+0200 I/BLUETOOTH_FRWK_API( 9148): bt-device.c: bluetooth_connect_le(354) >  ### Connect LE 
    01-10 17:25:36.199+0200 I/BLUETOOTH_FRWK_API( 9148): bt-device.c: bluetooth_connect_le(357) >  Async Request => type=BT_BLUEZ_SERVICE, fn=BT_CONNECT_LE(0x159) 01-10 17:25:36.209+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(163) > Method[service_request] Object Path[/org/projectx/bt_service] Interface Name[org.projectx.bt]
    01-10 17:25:36.209+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(224) > Request ID: 21
    01-10 17:25:36.209+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(236) > Service type = 0, fn = BT_CONNECT_LE (0x159)
    01-10 17:25:36.209+0200 E/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-adapter-le.c: _bt_hold_current_advertising(505) > It's NOT advertising
    01-10 17:25:36.209+0200 E/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-device.c: _bt_connect_le_device(1947) > Unable to hold advertising
    01-10 17:25:36.279+0200 D/BLUETOOTH_FRWK_API( 9148): bt-device.c: bluetooth_is_device_connected(320) > Sync Request => type=BT_BLUEZ_SERVICE, fn=BT_IS_DEVICE_CONNECTED(0x5a)
    01-10 17:25:36.329+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-device.c: __bt_connect_le_device_internal(1880) > Connect LE [6F:0B:DA:7A:B4:XX]
    01-10 17:25:36.329+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(279) > INSERT INTO REQ LIST
    01-10 17:25:36.329+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(163) > Method[service_request] Object Path[/org/projectx/bt_service] Interface Name[org.projectx.bt]
    01-10 17:25:36.329+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_service_method(236) > Service type = 0, fn = BT_IS_DEVICE_CONNECTED (0x5a)
    01-10 17:25:36.329+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-device.c: _bt_is_device_connected(1609) > 6F:0B:DA:7A:B4:XX connection_type: 64
    
    # I suppose that 1 means true and there is a connection.
    01-10 17:25:36.399+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-device.c: _bt_is_gatt_connected(1578) > gatt is connected : 1
    01-10 17:25:36.399+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-request-handler.c: __bt_bluez_request(926) > is_connected: 1
    01-10 17:25:36.399+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_primary_services(320) > +
    01-10 17:25:36.399+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-adapter.c: _bt_get_discovering_property(2803) > discoverable_v:0
    01-10 17:25:36.409+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event(44) > event_type [3], event [13]
    01-10 17:25:36.409+0200 D/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event(391) > Path : /org/projectx/bt/le/adapter
    01-10 17:25:36.409+0200 I/BLUETOOTH_FRWK_SERVICE( 2755): bt-service-event-sender.c: _bt_send_event(392) >  Signal : LEDiscoveryFinished 
    01-10 17:25:36.409+0200 D/BLUETOOTH_FRWK_API( 9148): bt-request-sender.c: __send_request_cb(300) > +
    01-10 17:25:36.409+0200 D/BLUETOOTH_FRWK_API( 9148): bt-request-sender.c: __bt_get_event_info(117) > service_function : BT_CONNECT_LE (0x159)
    01-10 17:25:36.409+0200 D/BLUETOOTH_FRWK_API( 9148): bt-request-sender.c: __send_request_cb(401) > -
    01-10 17:25:36.549+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 00001101-0000-1000-8000-00805f9b3400 [Unknown]
    01-10 17:25:36.549+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    01-10 17:25:36.589+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 89d3502b-0f36-433a-8ef4-c502ad55f8dc [Apple Media Service]
    01-10 17:25:36.589+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 3
    01-10 17:25:36.639+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 7905f431-b5ce-4e99-a40f-4b1e122d00d0 [Apple Notification Center Service]
    01-10 17:25:36.639+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 3
    01-10 17:25:36.689+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 0000180a-0000-1000-8000-00805f9b34fb [Device Information]
    01-10 17:25:36.689+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 2
    01-10 17:25:36.739+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 00001805-0000-1000-8000-00805f9b34fb [Current Time Service]
    01-10 17:25:36.739+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 2
    01-10 17:25:36.789+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 0000180f-0000-1000-8000-00805f9b34fb [Battery Service]
    01-10 17:25:36.789+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    01-10 17:25:36.839+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 9fa480e0-4967-4542-9390-d343dc5d04ae [Unknown]
    01-10 17:25:36.839+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    01-10 17:25:36.889+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : d0611e78-bbb4-4591-a5f8-487910ae4366 [Unknown]
    01-10 17:25:36.889+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    01-10 17:25:36.939+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 00001801-0000-1000-8000-00805f9b34fb [Generic Attribute]
    01-10 17:25:36.939+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 1
    01-10 17:25:36.989+0200 I/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(257) > ======> Service : 00001800-0000-1000-8000-00805f9b34fb [Generic Access]
    01-10 17:25:36.989+0200 D/BLUETOOTH_FRWK_API( 9148): bt-gatt-client.c: bluetooth_gatt_get_service_property(287) > Characteristics count : 2
    After that I see error logs from my app denoting that timeout has expired (I set 10 seconds to give enough time).

    As I see error happened on function wc_bt_get_gatt_client_service() with error code -61 (BT_ERROR_NO_DATA).
    01-10 17:25:36.179+0200 E/WECONN  ( 2498): <wc_bt_get_gatt_client_service:2007> ret : -61
    01-10 17:25:36.179+0200 E/WECONN  ( 2498): <__create_gatt_handle_into:1169> Fail wc_bt_get_gatt_client_service[9a3f68e0-86ce-11e5-a309-0002a5d5c51b]/[-61]
    I have no idea what is the mysterious UUID 9a3f68e0-86ce-11e5-a309-0002a5d5c51b and why it requested.

    Thank you in advance.
编辑者为: Oleksii Chekanin 10 1月, 2018
查看选择的答案

响应

10 回复
Yasin Ali

Hi,

You are working on "Gear connects to iPhone via Bluetooth LE".

There is an app named Gear S : The Samsung Gear S application connects Samsung Gear S2,

Gear S3 and Gear Sport to your mobile device.

Link: https://itunes.apple.com/us/app/samsung-gear-s/id1117310635?mt=8

Are you looking for similar features provided by this app?

Oleksii Chekanin

Hello Yasin Ali. Yes, my goal to connect Gear with iPhone via BLE. Also I know about Gear S, but my app must connect
devices by itself, not expecting connection by Gear S.

Yasin Ali

How are you planning on handling the connection establishment on iPhone side?
Did you write any iPhone app?
 

Oleksii Chekanin

Hello. Yes, I have an iPhone app who acts as a Peripheral device. It does all required steps to start advertise.
Please explain what do you mean by 'handling the connection'.

Oleksii Chekanin

The main question I have is why such error occured.
 

Fail wc_bt_get_gatt_client_service[9a3f68e0-86ce-11e5-a309-0002a5d5c51b]/[-61]

What is the Service with such UUID?

Armaan-Ul- Islam

Can't State the exact reason why such error is being thrown.

But, Following the trail of this post:

Gatt server implementation

I found the bt-gatt-client.c file on this link, You might like to check it out.

Oleksii Chekanin

Hello. Thank you for your comment. Your links are helpful.
I already found solution and wrote it here.

Steven Brown

Its really helpful link thanks for sharing with us. 

Mark as answer
Oleksii Chekanin
I found a solution. Put it here for all who will face it in future. Go to Gear S (Gear Manager on Android) app and connect phone with Gear. After that this error will not happen.
Toshiba Support

Thanks for your nice post, it’s so much very informative post. Currently, Bluetooth headphone technology is very popular. Today we are not comforted using a wire or cable. That’s why Bluetooth headphones are used by millions of people every day for work and play.  Bluetooth phone comes in the market besides Bluetooth headphone which works as like Bluetooth headphone.