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

4

10

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?

Solution answered 3/11, 2014 at 14:56 Comment(0)
T
8

BLE programming with BlueZ on Galileo or Edison is similar to any other x86 platform.

Edison (and Galileo) usually comes with BlueZ libraries pre-installed. You just need to link with them with your C code, and program similar to other x86 platform.

For a full C code example bluetooth scan with BlueZ, see this link.

Please see this example for BLE scan

And the HCI API here.

Tletski answered 4/11, 2014 at 3:36 Comment(3)
I've seen this code example. It works, but it doesn't scan BLE devices - only normal ones.Solution
@Solution For BLE you will need to set the hci_le_set_scan_parameter, please see this example for BLE scanTletski
The BLE example depends on ncurses, for testing, I changed it to be a pure console application. Also, you have to run it with sudo.Pudency
D
11

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

Dasher answered 21/5, 2015 at 18:59 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Vegetarianism
T
8

BLE programming with BlueZ on Galileo or Edison is similar to any other x86 platform.

Edison (and Galileo) usually comes with BlueZ libraries pre-installed. You just need to link with them with your C code, and program similar to other x86 platform.

For a full C code example bluetooth scan with BlueZ, see this link.

Please see this example for BLE scan

And the HCI API here.

Tletski answered 4/11, 2014 at 3:36 Comment(3)
I've seen this code example. It works, but it doesn't scan BLE devices - only normal ones.Solution
@Solution For BLE you will need to set the hci_le_set_scan_parameter, please see this example for BLE scanTletski
The BLE example depends on ncurses, for testing, I changed it to be a pure console application. Also, you have to run it with sudo.Pudency
M
5

The GattLib library (which was created after this question was asked) has the tools to scan/connect to BLE devices using C.

Manchu answered 18/6, 2020 at 18:8 Comment(0)
A
0

The intel-edison scan.c code also works on Raspberry Pi.

It works to scan for the Adafruit BLE UART friend module connected to the arduino Uno.

On the Pi, need to download the bluez-5.33.tar.gz, libncurses-dev and the libbluetooth-dev.

To compile scan.c, use

gcc scan.c -lbluetooth -o scan

Aubade answered 12/2, 2016 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.