语言

Menu
Sites
Language
Bluetooth using spp : solved

 

I'm trying to transfer Files such as Music, Document using Bluetooth SPP.

File Sending goes well, but there's some error in File Reception.

here's my example code.

this code is based on tutorial.

void bt_opp_server_transfer_progress_cb_for_opp(const char *file, long long size, int percent, void *user_data)
{
   dlog_print(DLOG_INFO, LOG_TAG, "file: %s", file);
   dlog_print(DLOG_INFO, LOG_TAG, "size: %ld", size);
   dlog_print(DLOG_INFO, LOG_TAG, "percent: %d", percent);
}

void bt_opp_server_transfer_finished_cb_for_opp(int result, const char *file, long long size, void *user_data)
{
   dlog_print(DLOG_INFO, LOG_TAG, "result: %d", result);
   dlog_print(DLOG_INFO, LOG_TAG, "file: %s", file);
   dlog_print(DLOG_INFO, LOG_TAG, "size: %ld", size);
}


void connection_requested_cb_for_opp_server(const char *remote_address, void *user_data)
{
   dlog_print(DLOG_INFO, LOG_TAG, "remote_address: %s", remote_address);
}

// File receive function
static void RECV_DATA(  ){

	bt_error_e ret;
	ret=	bt_initialize();

	if(ret!= BT_ERROR_NONE){
		   dlog_print(DLOG_ERROR, LOG_TAG, "[bt_initialize] Failed.");

	     errorTest(ret);

	}
	char caller_id_path[1024] = {'\0', };
	char* resource_path=NULL;
		resource_path = app_get_data_path();
		snprintf(caller_id_path, sizeof(caller_id_path)-1, "%s", resource_path);
		free(resource_path);
	ret = bt_opp_server_initialize_by_connection_request (caller_id_path, connection_requested_cb_for_opp_server, NULL);
	if (ret != BT_ERROR_NONE)
	{
	   dlog_print(DLOG_ERROR, LOG_TAG, "[bt_opp_server_initialize_by_connection_request] Failed.");
	     errorTest(ret);
	}

         int transferID;
	 ret = bt_opp_server_accept(bt_opp_server_transfer_progress_cb_for_opp,
	                            bt_opp_server_transfer_finished_cb_for_opp,
	                            NULL, NULL, &transferID);
	 if (ret != BT_ERROR_NONE)
	   {
	      dlog_print(DLOG_ERROR, LOG_TAG, "[bt_opp_server_accept] Failed.");
	      errorTest(ret);
	   }

	bt_opp_server_deinitialize();

	bt_deinitialize();

}

in bt_opp_server_accept , it returns BT_ERROR_OPERATION_FAILED

  I want to know why bt_opp_server_accept fails, and why I can't receive File from another Bluetooth Device.

 Thank you in advance.

 

==============================================================================================================

I solved my problem.

 

void bt_opp_server_transfer_progress_cb_for_opp(const char *file, long long size, int percent, void *user_data)
{
   dlog_print(DLOG_INFO, "DIT", "file: %s", file);
   dlog_print(DLOG_INFO, "DIT", "size: %ld", size);
   dlog_print(DLOG_INFO, "DIT", "percent: %d", percent);
}

void bt_opp_server_transfer_finished_cb_for_opp(int result, const char *file, long long size, void *user_data)
{
   dlog_print(DLOG_INFO, "DIT", "result: %d", result);
   dlog_print(DLOG_INFO, "DIT", "file: %s", file);
   dlog_print(DLOG_INFO, "DIT", "size: %ld", size);
}

void connection_requested_cb_for_opp_server(const char *remote_address, void *user_data)
	{
		bt_error_e ret;
	   dlog_print(DLOG_INFO, "DIT", "remote_address: %s", remote_address);


		 ret = bt_opp_server_accept(bt_opp_server_transfer_progress_cb_for_opp,
		                            bt_opp_server_transfer_finished_cb_for_opp,
		                            NULL, NULL, NULL);
		 if (ret != BT_ERROR_NONE)
		   {
		      dlog_print(DLOG_ERROR, "DIT", "[bt_opp_server_accept] Failed.");
		      errorTest(ret);
		   }

	}

// file receiving function 
int BTRecv() {


		bt_error_e ret;
		ret=	bt_initialize();
		if(ret!= BT_ERROR_NONE){
			   dlog_print(DLOG_ERROR, "DIT", "[bt_initialize] Failed.");
			   errorTest(ret);
		     return -1;

		}
		ret = bt_opp_server_initialize_by_connection_request (DOWNLOADSFOLDERPATH, connection_requested_cb_for_opp_server, NULL);
		if (ret != BT_ERROR_NONE)
		{
		   dlog_print(DLOG_ERROR, "DIT", "[bt_opp_server_initialize_by_connection_request] Failed.");
		   errorTest(ret);
		     return -1;
		}
		return 0;
}

 

 Tutorial was Hard to UnderStand.....

bt_opp_server_accept must be called when connection_requested_cb_for_opp_server is called, 

so I put bt_opserver_accept in body of connection_requested_cb_for_opp_server, and it works well ;)

编辑者为: BeomChan Park 07 7月, 2015

响应

2 回复
Jean Yang

Hi, 

Did you add the the privilege of bluetooth?

BeomChan Park

yes I did  http://tizen.org/privilege/bluetooth