Bluetooth rfcomm server - Raspberry Pi Forums


hello guys! want send data android phone raspberry pi. have couple questions , hope kind enough me:
-how hard-code connection between 2 devices? want skip scanning part because not scanning devices in project.
-this example found in book bluetooth connections. how can adapt make work?(assuming android part done well)

code: select all

#include <stdio.h> #include <unistd.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> #include <bluetooth/rfcomm.h>  int main(int argc, char **argv) { 	struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 }; 	char buf[1024] = { 0 }; 	int s, client, bytes_read; 	unsigned int opt = sizeof(rem_addr); 	 	//allocate socket 	s = socket(af_bluetooth, sock_stream, btproto_rfcomm); 	 	//bind socket port 1 of first available adapter  	bdaddr_t tmp = {0,0,0,0,0,0}; 	 	loc_addr.rc_family = af_bluetooth; 	loc_addr.rc_bdaddr = tmp; 	loc_addr.rc_channel = 1; 	bind(s, (struct sockaddr* )&loc_addr, sizeof(loc_addr)); 	 	//put socket listening mode 	listen(s, 1); 	 	//accept 1 connection 	client = accept(s, (struct sockaddr *)&rem_addr, &opt); 	 	ba2str( &rem_addr.rc_bdaddr, buf ); 	fprintf( stderr, "accepter connection %s\n", buf); 	memset( buf, 0, sizeof(buf)); 	 	//read data client  	bytes_read = recv(client, buf, sizeof(buf), 0); 	if( bytes_read > 0 ) 	{ 		printf("received [%s]\n", buf); 	} 	 	//close connection 	close(client); 	close(s); 	return 0; } 

bump.


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code