Connecting to Bluetooth LE devices from raspberry pi using Bluez libraries in C language

5.4k views Asked by At

I am using my raspberry pi to perform LEScan at fixed intervals and connect to new found BLE devices. Performing a general scan is easy and can be easily done by using the bluez libraries. http://people.csail.mit.edu/albert/bluez-intro/x45.html

But i can't figure out how to perform LE scan using Bluetooth programming in C language.

I have to find new BLE devices, connect to them and receive json data from the connected devices.

2

There are 2 answers

1
Jagdish On

The link you are pointing is for classic bluetooth;for BLE lescan go

through scantest.c in link

https://github.com/carsonmcdonald/bluez-experiments/tree/master/experiments

0
OlivierM On

To write a C program to scan BLE devices you can have a look at BlueZ hcitool sources.

To connect to the BLE device and interact with the GATT protocol you can either use the experimental DBUS Bluez API in Bluez v5.x (recommended to use v5.39+) or use a library like 'gattlib'.