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?

0andriy
  • 4,183
  • 1
  • 24
  • 37
Longes
  • 113
  • 1
  • 1
  • 4

4 Answers4

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

Community
  • 1
  • 1
Yao Hao
  • 151
  • 1
  • 4
  • 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. – Kmeixner May 21 '15 at 19:16
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.

ashoke
  • 6,441
  • 2
  • 26
  • 25
  • 2
    I've seen this code example. It works, but it doesn't scan BLE devices - only normal ones. – Longes Nov 04 '14 at 09:08
  • @Longes For BLE you will need to set the `hci_le_set_scan_parameter`, [please see this example for BLE scan](https://github.com/carsonmcdonald/bluez-experiments/blob/master/experiments/scantest.c) – ashoke Nov 04 '14 at 18:06
  • 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. – prmottajr Nov 25 '15 at 13:21
5

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

emack
  • 51
  • 1
  • 2
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