2

I am reposting this again in case missed out.

i have installed

sudo apt-get install libbluetooth-dev

and tried to compile btgatt-client.c from Blue5.54/tools/ with

gcc -o btgatt-client btgatt-client.c -lbluetooth

but get '#include "lib/bluetooth.h":no such file or directory'

What could be missing.I have tried move the files from '/usr/include/bluetooth' the compilation folder but seems doesn't work. I am also curious where does this "src/shared/mainloop" from?

I am able to run the example and connect to nrf app but unable to compile the .c file.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • If that's in your include path, then use `#include <...>`. If it's in your source dir use `#include "..."`. – tadman Jun 30 '20 at 09:53
  • Yes tried it. I tried from the source dir as well but it still cannot find the dependencies. – R.M.S.Sundram Jun 30 '20 at 10:51
  • 1
    This is where `-I` comes in handy to specify where those source header files are. – tadman Jun 30 '20 at 10:53
  • Well, there is only onfy one `lib` folder in bluez, so I guess add `-I` the directory.. but why not just use the auttools that come with the project? – KamilCuk Jun 30 '20 at 11:03
  • @tadman Well.This is my 1st time touching it. Successfully controlled via Bluetoothctl haha. Hope can get some guidance. I felt the Python lib has some issues so went to C. – R.M.S.Sundram Jun 30 '20 at 11:11
  • @KamilCuk - Where this file is located.AFAIK i can see Python script and C. – R.M.S.Sundram Jun 30 '20 at 11:12
  • [lib](https://github.com/bluez/bluez/tree/master/lib) is a directory. Which file? [autotools](https://en.wikipedia.org/wiki/GNU_Autotools) is a build system. Please read about it and the readme in [bluez project](https://github.com/bluez/bluez) - it explains how to compile and configure the project – KamilCuk Jun 30 '20 at 11:22
  • 1
    @KamilCuk yup know about dir. Alright will check on that. Thank you :) – R.M.S.Sundram Jun 30 '20 at 12:36

2 Answers2

1

The source files in BlueZ are not designed to be compiled singularly. Instead, you are supposed to build and install the entire BlueZ source, which in turn will compile btgatt-client.c for you. Please see the link below for instructions on how to build the entire BlueZ source:-

How to rebuild bluez

You will probably find that you need to install a lot of dependencies along the way, but you can either install these using sudo apt-get install <dependency> or try and not include it in the build. For example, to build BlueZ without systemd, you can do the following:-

./configure --disable-systemd
make

I hope this helps.

Youssif Saeed
  • 11,789
  • 4
  • 44
  • 72
  • Thank you for the guidance! Appreciate most. However just curios..the python script that came with BlueZ has issue in connecting to nrf app.Does this mean the script is not running well on RPI 3B+ or is there any setting which i missed out? Thank you again – R.M.S.Sundram Jul 02 '20 at 08:17
  • The issue is i can see the example showing but unable to connect to it via nrf app. – R.M.S.Sundram Jul 02 '20 at 09:14
  • What are you trying to do and why do you need the btgatt-client.c specifically? Please note that the gatt client example means that you have to connect from the gatt client to the nrf app and not the other way around. – Youssif Saeed Jul 02 '20 at 20:52
  • Thanks for asking Youssif. I need to use btgatt-client or btgatt-server to get/send information to BLE-MCU such as ESP32. So for now i am more focused on client part which the RPI will be btgatt client and ESP32 (or NRF) as btgattserver. I know how the BLE protocol works but the problem is, like i mentioned before i have tried to run Python examples (in this case gattserver.py) which outputs dummy heartrate that can be seen in nrf app. – R.M.S.Sundram Jul 03 '20 at 03:16
  • I can advertise from RPI but i have issue connecting from nrf app.It produce 0x08 (connection timeout). However when i use the C source from Bluez5.54 > tools > btgatt.o, i don't have such issue although i enable hciconfig hcix down,up, leadv 0 & 3. This is something that i can't figure out. The reason why i am looking at python is that after referring the data it need to be sent over to server. The server side use Python so that why i plan to synch the development code. – R.M.S.Sundram Jul 03 '20 at 03:19
  • I don't know if there are python applications that are mature enough to do what you need. My recommendation is to implement the gatt client using "gatttool" commands (example here: https://stackoverflow.com/q/15657007/2215147) and the gatt server using "bluetoothctl" comands (example here: https://stackoverflow.com/a/52982329/2215147) – Youssif Saeed Jul 03 '20 at 06:19
  • Ow ok. So the existing python scripts that comes with BlueZ is not stable and still experimental and education use? Thats bad :( . Yeah like you said i have used the so called 'depreciated 'gatttool' to and later 'Bluetoothctl' . Both works fine. And i also see possibility of using it by using command wrappers like Pexpect. But how come i can see a lot of people using python script to do the operation like this [link](https://scribles.net/running-ble-gatt-server-example-on-raspbian-stretch/) .I tried but no success neither. – R.M.S.Sundram Jul 03 '20 at 09:18
  • Lets say in the future i need to connect to both Classic & LE protocol...still will be bluetoothctl? I don't worry much about the server part for now. But need to solve the bluetooth connection issue 1st – R.M.S.Sundram Jul 03 '20 at 09:19
  • Honestly I don't have much experience with using python with BlueZ so I can't help you there unfortunately. Yes bluetoothctl can be used with classic Bluetooth, but you can also use other BlueZ tools such as sdptool and rfcomm. These are deprecated as well but have a lot of resources on how they are used, unlike bluetoothctl which is relatively new. – Youssif Saeed Jul 03 '20 at 11:20
0

@Youssif Saeed. Thanks for the replies.

The good news is i have found out the cause.It seems the BlueZ bluetooth stack has an issue running in Raspbian Buster. I have downgrade the OS to Stretch and all seems up and running.

However i am trying gatt-client example and seems like not working when i set nrf app to advertising mode with exact UUID as in example. Or maybe i missed out certain part.Going to give a try with a simpler device like ESP32.

UPDATED

Thanks again guys.DBus gatt-client able to connect to BLMCU's. They key of operation is it needs to be paired > connected and read the BLE Server