Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.

RPi zero 2W bluez and C
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

RPi zero 2W bluez and C

by cydrollinger on Sun Nov 28, 2021 11:52 am

So, I have been fishing around for information about connecting bluetooth low energy devices to an rpi zero 2 W. I came across a few sources of information, and an adafruit tutorial has been as good as any, but imcomplete and now outdated.

https://learn.adafruit.com/install-blue ... stallation
https://people.csail.mit.edu/albert/blu ... index.html
https://www.bluetooth.com/bluetooth-res ... ovisioner/

So, I have successfully scanned bluetooth devices on the rpi zero 2 W after following the adafruit tutorial and testing an example program simplescan.c from https://people.csail.mit.edu/albert/blu ... /c404.html all from within buster lite.

So, it is possible to control the bluetooth radio and resources on an rpi from C programs, but the ability to do it without installing the latest bluez and relying on the preinstalled bluez on current rpi os has not been successful by me. Modern rpi os will allow me to compile and run helloworld.c it will not compile the simplescan.c program on account the reference to bluetooth/bluetooth.h header can not included.
I have been fishing for information about the official bluestack for linux: bluez and its location within the modern rpi os. I can find refences to bluetooth in /sys/module but the actual bluez folder and more specifically bluetooth.h is a mystery.

QUESTIONS: on modern rpi os is bluez the bluetooth stack or library used to control the bluetooth radio and resource? If so, where is it located, specifically the bluetooth.h file? Would there be any reason I could not create the simplescan.c file within that location compile and run with the same success I have seen thus far? Ultimately, I would like to utilize the recipe from Bluetooth Sig to manage a bluetooth mesh network. Is this reasonable?

Posts: 1
Joined: Sun Nov 28, 2021 11:14 am

Re: RPi zero 2W bluez and C

by mikeysklar on Mon Nov 29, 2021 7:41 pm

bluez and bluezutils are the official Linux Bluetooth protocol stack + utilities.


This package contains tools and system daemons for using Bluetooth devices. BlueZ is the official Linux Bluetooth protocol stack. It is an Open Source project distributed under GNU General Public License (GPL).

I use bluetoothctl on my Pi's to scan for other BLE devices and learn about their services. Example below.

Code: Select all | TOGGLE FULL SIZE
pi@pidev:~ $ sudo bluetoothctl
Agent registered
[Logitech X50]# scan on
Discovery started
[CHG] Controller DC:A6:32:D2:9A:90 Discovering: yes
[NEW] Device CC:FD:D2:4F:82:1D Xtactor
[NEW] Device 70:81:53:04:20:4F 70-81-53-04-20-4F
[NEW] Device 4F:13:A6:7A:67:B6 4F-13-A6-7A-67-B6
[NEW] Device A0:38:F8:AD:39:D0 oura_A038F8AD39D0
[Logitech X50]# connect CC:FD:D2:4F:82:1D
Attempting to connect to CC:FD:D2:4F:82:1D
[CHG] Device CC:FD:D2:4F:82:1D Connected: yes
Connection successful

Code: Select all | TOGGLE FULL SIZE
# scan off
Discovery stopped
[CHG] Controller DC:A6:32:D2:9A:90 Discovering: no
[CHG] Device D1:72:15:C7:30:93 RSSI is nil
[CHG] Device A0:38:F8:AD:39:D0 RSSI is nil
[CHG] Device 40:6C:1E:DB:DB:84 TxPower is nil
[CHG] Device 40:6C:1E:DB:DB:84 RSSI is nil
[CHG] Device 74:C1:D2:DD:04:D6 TxPower is nil
[CHG] Device 74:C1:D2:DD:04:D6 RSSI is nil

Code: Select all | TOGGLE FULL SIZE
[Xtactor]# info
Device CC:FD:D2:4F:82:1D (random)
        Name: Xtactor
        Alias: Xtactor
        Appearance: 0x03c0
        Paired: no
        Trusted: no
        Blocked: no
        Connected: yes
        LegacyPairing: no
        UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
        UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
        UUID: Device Information        (0000180a-0000-1000-8000-00805f9b34fb)
        UUID: Battery Service           (0000180f-0000-1000-8000-00805f9b34fb)
        UUID: Nordic Semiconductor ASA  (0000fe59-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (8ec9f001-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00a-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00b-f315-4f60-9fb8-838830daea50)
        UUID: Vendor specific           (8ec9f00d-f315-4f60-9fb8-838830daea50)
        RSSI: -61

Posts: 6487
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.