Hi everybody,
I'm trying to implement a simple ble gatt server with one service containing one characteristics using tizen studio for the samsung gear S3. I followed what i could find on the docs but it doesn't seems to work and now i'm a bit lost. Here my code:
if(bt_initialize() == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Bluetooth initialized successfully."); bt_adapter_state_e state = BT_ADAPTER_DISABLED; int ret = bt_adapter_get_state(&state); if (state == BT_ADAPTER_ENABLED) dlog_print(DLOG_INFO, LOG_TAG, "Bluetooth adapter initialized successfully."); // Creating gatt service if(bt_gatt_server_initialize() == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Gatt server initialized successfully."); int retval = bt_gatt_server_create(&(ad->gatt_server_handler)); if(retval == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Gatt server created successfully."); if(bt_gatt_service_create(MIL_SERVICE_UUID, BT_GATT_SERVICE_TYPE_PRIMARY, &(ad->service_handler)) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Gatt service created successfully."); if(bt_gatt_server_register_service(ad->gatt_server_handler, ad->service_handler) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Service successfully added to gatt server."); const char* char_val = "50"; if(bt_gatt_characteristic_create(MIL_CHARACTERISTIC_UUID, BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE, BT_GATT_PROPERTY_READ | BT_GATT_PROPERTY_WRITE | BT_GATT_PROPERTY_NOTIFY, char_val, 8, &(ad->characteristic_handler)) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Characteristic created successfully."); if(bt_gatt_service_add_characteristic(ad->service_handler, ad->characteristic_handler) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Characteristic successfully added to service."); if(bt_adapter_le_create_advertiser(&(ad->advertiser_handler)) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Advertiser successfully created."); const char *serviceUUID = "180F"; int ret = bt_adapter_le_add_advertising_service_uuid(ad->advertiser_handler, BT_ADAPTER_LE_PACKET_ADVERTISING, serviceUUID); if(ret == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Service successfully added to advertiser."); if(bt_adapter_le_set_advertising_device_name(ad->advertiser_handler, BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true) == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Device name successfully added to advertiser."); int ret = bt_adapter_le_start_advertising_new(ad->advertiser_handler, NULL, NULL); if(ret == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Advertiser successfully started."); } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when starting advertiser! %d", ret); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding device name to advertiser!"); } } else { char* errMsg = get_error_message(ret); dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding service to advertiser! %d", ret); dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding service to advertiser! %s", errMsg); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when creating advertiser!"); } if(bt_gatt_server_start() == BT_ERROR_NONE) { dlog_print(DLOG_INFO, LOG_TAG, "Gatt server successfully started."); } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when starting gatt server!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding characteristic to service!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when creating characteristic!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when adding service to gatt server!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when creating gatt service!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when creating gatt server!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when initializing gatt server!"); } } else { dlog_print(DLOG_ERROR, LOG_TAG, "Error occurred when initializing bluetooth!"); }
I know my code isn't very digest but i just wanted to test quickly how to setup the whole gatt and clean up the code when this works. There aren't any errors in my log but sadly when i try to see this new service using a ble sniffer on my phone it doesn't show up (only the 2 basic services are showing up). Here my log:
06-26 08:18:24.189 : INFO / milservice ( 4679 : 4679 ) : Bluetooth initialized successfully.
06-26 08:18:24.209 : INFO / milservice ( 4679 : 4679 ) : Bluetooth adapter initialized successfully.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Gatt server initialized successfully.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Gatt server created successfully.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Gatt service created successfully.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Service successfully added to gatt server.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Characteristic created successfully.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Characteristic successfully added to service.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Advertiser successfully created.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Service successfully added to advertiser.
06-26 08:18:24.229 : INFO / milservice ( 4679 : 4679 ) : Device name successfully added to advertiser.
06-26 08:18:24.449 : INFO / milservice ( 4679 : 4679 ) : Advertiser successfully started.
06-26 08:18:24.459 : INFO / milservice ( 4679 : 4679 ) : Gatt server successfully started.
I don't know what i'm missing or if i do something wrong..