How to perform a bluetooth low-energy scan via BlueZ C library

Longes picture Longes · Nov 3, 2014 · Viewed 34.4k times · Source

I'm new in programming Bluetooth low energy using BlueZ.

I want to develop a native code c to scan nearby devices using a BlueZ API for Bluetooth low energy on Intel Edison. I've seen this question, but the answer doesn't really help. Any advice?

Answer

Yao Hao picture Yao Hao · May 21, 2015

The example on the other answer does not work for me, it stops in Scanning...

The next link works for c language, but has an error when casting the bytes that have the information about de rssi signal. https://github.com/glock45/intel-edison-playground/blob/master/scan.c

this line 121:

printf("%s - RSSI %d\n", addr, (**char**)info->data[info->length]);

should be:

printf("%s - RSSI %d\n", addr, (**int8_t**)info->data[info->length]);

I found these by looking inside bluez-version/monitor/*.c, where btmon program is. You can see the data types and structs, hcidump.c is very useful and packets.c, and main.c too, but there are many to learn about the hci sockets