rtnpro starts his blueZ journey...

Just now … I wrote my first ever blueZ code, a simple one though, that too, from an online  tutorial at


Its a nice tutorial for newbies like me to get started with blueZ.

First of all, I needed to setup my blueZ development environment. Since I use Fedora 10, I did the following

yum install -y bluez-libs bluez-libs-devel libgdbus libgdbus-devel

Also, one can manually install it from the source packages available at


The first code that I wrote is a simplescan.c which scans for bluetooth devices in proximity and displays its bluetooth address ( a 48-bit address unique for all bluetooth devices managed by IEEE). Here’s the following code :



int main(int argc, char **argv)
inquiryinfo *ii = NULL;
int max
rsp, numrsp;
int dev
id, sock, len, flags;
int i;
char addr[19] = {0};
char name[248] = {0};

devid = hcigetroute(NULL);
sock = hci
opendev( devid);
if (dev_id < 0 || sock < 0){
perror(“opening socket”);

len = 8;
maxrsp = 255;
flags = IREQ
ii = (inquiry
info*)malloc(maxrsp * sizeof(inquiryinfo));

numrsp = hciinquiry(devid, len, maxrsp, NULL, &ii, flags);
if( numrsp < 0 ) perror(“hciinquiry”);

for (i = 0; i < numrsp; i++) {
ba2str(&(ii+i)->bdaddr, addr);
memset(name, 0, sizeof(name));
if (hci
readremotename(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0)
strcpy(name, “[unknown]”);
printf(“%s %sn”, addr, name);
close( sock );
return 0;

Then to compile the code :

[rtnpro@xps blueZ]$ gcc -o simplescan simplescan.c -lbluetooth

Then to execute it :

[rtnpro@xps blueZ]$ ./simplescan

00:1D:98:78:A2:A1 Nokia 5310 XpressMusic

See the output, its my Nokia mobile phone.

Check the next post: Really inspiring!!! »

Share on:
comments powered by Disqus