Community
cancel
Showing results for 
Search instead for 
Did you mean: 
akham2
Novice
1,831 Views

sdp_record_register function doesn't work

Jump to solution

hi,

I have been using bluez library included by Intel Edison.My problem is when I try to register a service using sdp_record_register, it blocks the sketch and doesn't make any progress. In the following or attached code you can see that I have put a print statement after the function but it doesn't print. Any suggestions please?

regards,

Abdulrahman

1 Solution
akham2
Novice
115 Views

Finally I found the solution. The problem was not in the code. I just needed to modify bluetooth.service file ( I added -C after bluetoothd) and boom it worked.

Thanks for your help I really appreciate it.

View solution in original post

4 Replies
akham2
Novice
115 Views

the problem in register_service() function

the code:

# include

# include

# include

# include

# include

# include

# include

# include

# include

# include

# include

//# define ADD_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})

//# define ADD_ALL (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})

//# define ADD_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})

LiquidCrystal lcd(8,9,4,5,6,7);

char buf[1024];

char addr[19];

char name[248];

bdaddr_t Add_Any = {{0, 0, 0, 0, 0, 0}};

bdaddr_t Add_Loc = {{0, 0, 0, 0xff, 0xff, 0xff}};

bdaddr_t *ptrAny;

bdaddr_t *ptrLoc;

/*

struct sockaddr_rc loc_addr, rem_addr;

int s, client, bytes_read;

int bndError, listError;

socklen_t opt;

*/

void setup() {

lcd.begin(16, 2);

Serial.begin(9600);

lcd.print("Welcome");

delay(3000);

ptrAny = &Add_Any;

ptrLoc = &Add_Loc;

register_service();

//opt = sizeof(rem_addr);

addr[19] = { 0 };

name[248] = { 0 };

//loc_addr = { 0 };

//rem_addr = { 0 };

buf[1024] = { 0 };

/*

// allocate socket

s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// bind socket to port 1 of the first available

// local bluetooth adapter

loc_addr.rc_family = AF_BLUETOOTH;

loc_addr.rc_bdaddr = *ptrAny;

loc_addr.rc_channel = (uint8_t) 11;

bndError = bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

// put socket into listening mode

listError = listen(s, 1);

Serial.println("setup done");

Serial.println("Socket ");

Serial.print(s);

Serial.println("bind ");

Serial.print(bndError);

Serial.println("listen ");

Serial.print(listError);

*/

lcd.clear();

lcd.print("done setup");

delay(10000);

}

void loop() {

lcd.clear();

Serial.println("done setup");

/*

// accept one connection

client = accept(s, (struct sockaddr *)&rem_addr, &opt);

Serial.println("accept ");

Serial.print(client);

if(client > 0){

ba2str( &rem_addr.rc_bdaddr, buf );

lcd.clear();

lcd.setCursor(0,0);

lcd.print("con request from");

lcd.setCursor(0,1);

lcd.print(buf);

delay(2000);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("conected");

delay(2000);

while(1){

lcd.clear();

lcd.setCursor(0,0);

lcd.print("waitng for");

lcd.setCursor(0,1);

lcd.print("command");

delay(1000);

memset(buf, 0, sizeof(buf));

// read data from the client

bytes_read = read(client, buf, sizeof(buf));

Serial.println("read ");

Serial.print(bytes_read);

if( bytes_read > 0 ) {

lcd.clear();

lcd.setCursor(0,0);

lcd.print(buf);

delay(2000);

}

}

}

*/

}

// setup and register service 77FE183EA9D911E5ACA9C2AE1D5D46B0

//sdp_session_t *register_service()

void register_service(){

//Serial.println("hi ");

uint32_t service_uuid_int[] = { 0, 0, 0, 0x77FE183EA9D911E5ACA9C2AE1D5D46B0};

uint8_t rfcomm_channel = 11;

const char *service_name = "Edison";

const char *service_dsc = "An experiment about bluetooth";

const char *service_prov = "Abdul";

uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid;

sdp_list_t *l2cap_list = 0,

*rfcomm_list = 0,

*root_list = 0,

*proto_list = 0,

*access_proto_list = 0;

sdp_data_t *channel = 0, *psm = 0;

sdp_record_t *record = sdp_record_alloc();

// set the general service ID

sdp_uuid128_create( &svc_uuid, &service_uuid_int );

sdp_set_service_id( record, svc_uuid );

// make the service record publicly browsable

sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);

root_list = sdp_list_append(0, &root_uuid);

sdp_set_browse_groups( record, root_list );

// set l2cap information

sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);

l2cap_list = sdp_list_append( 0, &l2cap_uuid );

proto_list = sdp_list_append( 0, l2cap_list );

// set rfcomm information

sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);

channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel);

rfcomm_list = sdp_list_append( 0, &rfcomm_uuid );

sdp_list_append( rfcomm_list, channel );

sdp_list_append( proto_list, rfcomm_list );

// attach protocol information to service record

access_proto_list = sdp_list_append( 0, proto_list );

sdp_set_access_protos( record, access_proto_list );

// set the name, provider, and description

sdp_set_info_attr(record, service_name, service_prov, service_dsc);

int err = 0;

sdp_session_t *session = 0;

// connect to the local SDP server, register the service record, and

// disconnect

session = sdp_connect( ptrAny, ptrLoc, SDP_RETRY_IF_BUSY );

err = sdp_record_register(session, record, 0);

lcd.clear();

lcd.print("Stop here");

// cleanup

sdp_data_free( channel );

sdp_list_free( l2cap_list, 0 );

sdp_list_free( rfcomm_list, 0 );

sdp_list_free( root_list, 0 );

sdp_list_free( access_proto_list, 0 );

//return session;

}

/*0x77FE183EA9D911E5ACA9C2AE1D5D46B0

0x71ECA406A9D911E5B96AB3AE1D5D46B0*/

Pedro_M_Intel
Employee
115 Views

Hello ENG_akhamis,

I found the following discussion on a quick search on Google, I believe it might help you, it looks like a very similar issue to yours.

http://sourceforge.net/p/bluez/mailman/message/14322925/ BlueZ / Mailing Lists

I'm not very familiar with this specific method of BlueZ, and since it's directly related to BlueZ, my best suggestion is that you contact them for help.

http://www.bluez.org/contact/ BlueZ " Contact

Peter.

Carlos_M_Intel
Employee
115 Views

Hi Eng_akhamis

Do you still having problems with your code?

Did you check Peter's suggestion?

Regards,

Charlie

akham2
Novice
116 Views

Finally I found the solution. The problem was not in the code. I just needed to modify bluetooth.service file ( I added -C after bluetoothd) and boom it worked.

Thanks for your help I really appreciate it.

View solution in original post

Reply