Issue while creating multiple service in BLE GATT service table example

Ashvajit.P
Posts: 34
Joined: Fri Feb 26, 2021 9:03 am

Issue while creating multiple service in BLE GATT service table example

Postby Ashvajit.P » Tue Aug 16, 2022 9:03 am

Hello,
i want to add multiple service in the given BLE service table example. I tried to create another table and created attribute table manually, but before staring the 2nd service my device starts advertising and after connection I am not able to see the 2nd service that has been created.
ble_servie_table.PNG
BLE service table log
ble_servie_table.PNG (61.52 KiB) Viewed 1342 times
The event after creating first attribute table

Code: Select all

        case ESP_GATTS_CREAT_ATTR_TAB_EVT:{
	        static bool SEC_service_Created = false;

	        if(0 == RB_service_handle[IDX_SVC])
	        {

		        if (param->add_attr_tab.status != ESP_GATT_OK) {
			        ESP_LOGE(GATTS_TABLE_TAG, "create attribute table failed, error code=0x%x", param->add_attr_tab.status);
		        }
		        else if (param->add_attr_tab.num_handle != RB_IDX_NB) {
			        ESP_LOGE(GATTS_TABLE_TAG,
				        "create attribute table abnormally, num_handle (%d) \
			                doesn't equal to RB_IDX_NB(%d)",
				        param->add_attr_tab.num_handle,
				        RB_IDX_NB);
		        }
		        else {
			        ESP_LOGI(GATTS_TABLE_TAG, "create attribute table successfully, the number handle = %d\n", param->add_attr_tab.num_handle);
			        memcpy(RB_service_handle, param->add_attr_tab.handles, sizeof(RB_service_handle));
			       //esp_err_t errz = esp_ble_gatts_start_service(RB_service_handle[IDX_SVC]);
			        esp_log_buffer_hex(GATTS_TABLE_TAG, RB_service_handle, RB_IDX_NB);
			       // if (errz != ESP_OK)
			       // {
				   //     ESP_LOGE(GATTS_TABLE_TAG, " GATTS start service failure : %d", errz);
		           // 
			       // } 
		        }
	        }
	        if (0 != RB_service_handle[IDX_SVC])
	        {
		        if (SEC_service_Created == false)
		        {

			        esp_err_t create_attr_ret = esp_ble_gatts_create_attr_tab(deivce_info_gatt_db, gatts_if, DEV_IDX_NB, SVC2_INST_ID);
			        ESP_LOGI(GATTS_TABLE_TAG, "Creating 2nd service table");
			        if (create_attr_ret)
			        {
				        ESP_LOGE(GATTS_TABLE_TAG, "create attr table failed, error code = %x", create_attr_ret);
			        }
			        else 
			        {
				        SEC_service_Created = true;
				        ESP_LOGI(GATTS_TABLE_TAG, "create  2nd attribute table successfully, the number handle = %d\n", param->add_attr_tab.num_handle);
				        memcpy(RB_Dev_Service_handle, RB_service_handle, RB_IDX_NB);
				        memcpy(RB_Dev_Service_handle + RB_IDX_NB, param->add_attr_tab.handles, DEV_IDX_NB);
			        }
		        }
		        if (SEC_service_Created == true)
		        {

			        if (param->add_attr_tab.status != ESP_GATT_OK) {
				        ESP_LOGE(GATTS_TABLE_TAG, "create attribute table failed, error code=0x%x", param->add_attr_tab.status);
			        }
			        else if (param->add_attr_tab.num_handle !=  DEV_IDX_NB) {
				        ESP_LOGE(GATTS_TABLE_TAG,
					        "create attribute table abnormally, num_handle (%d), doesn't equal to DEV_IDX_NB(%d)",
					        param->add_attr_tab.num_handle,
					        DEV_IDX_NB);
			        }
			        else {
				       
				        esp_err_t errz = esp_ble_gatts_start_service(RB_Dev_Service_handle[IDX_SVC]);
				        esp_log_buffer_hex(GATTS_TABLE_TAG, RB_Dev_Service_handle, RB_IDX_NB + DEV_IDX_NB);
				        if (errz != ESP_OK)
				        {
					        ESP_LOGE(GATTS_TABLE_TAG, " GATTS start service failure : %d", errz);
		            
				        } 
			        }
		        }

	        }
               
	        	        
            break;
        }
Is there any example or reference from where I can see multiple service added by using service table ?

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 229 guests