I'm trying to do some Bluetooth programming with two Raspberrys but I'm not sure what packets/libraries or such things I need to install. I have usb bluetotooth dongles and ran this command: sudo apt-get install bluetooth bluez-utils blueman.
I thought I would be fine with this but when I try to compile simplescan.c from here http://people.csail.mit.edu/rudolph/Tea ... BTBook.pdf, I get fatal error: bluetooth/bluetooth.h: no such file or directory, compilation terminated.
I would be very thankful if someone could help me!
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
I don't 'do' C, but I can google an error message with the best of 'em: http://stackoverflow.com/questions/2343 ... d-in-linux
They suggest
They suggest
Code: Select all
sudo apt-get install libbluetooth-dev
Re: Bluetooth C programming
There is probably a "dev" library to install as well. That will include the "c" header files. I can't check on a pi at the moment (writing new image to micro sd-cardlihakimpale wrote: sudo apt-get install bluetooth bluez-utils blueman.
I thought I would be fine with this but when I try to compile simplescan.c from here http://people.csail.mit.edu/rudolph/Tea ... BTBook.pdf, I get fatal error: bluetooth/bluetooth.h: no such file or directory, compilation terminated.

"libbluetooth-dev - Development files for using the BlueZ Linux Bluetooth library"
so I would expect "sudo apt-get install libbluetooth-dev" to work.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
Ok thank you very much.
I am compiling the code using arm-linux-gnueabihf cross compiler from my Ubuntu laptop with eclipse. I think I need the .a file for the linker but I can't find it anywhere.
I am compiling the code using arm-linux-gnueabihf cross compiler from my Ubuntu laptop with eclipse. I think I need the .a file for the linker but I can't find it anywhere.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
I have done some research and found out that .so file is for same function and there should be somewhere libbluetooth.so.2 file but I can't find it. I have searched all the lib directories but can't find it. I'm assuming I should find those files from lib directory.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
I think it should be in /usr/local/lib directory but it isn't.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
I found the files. They were in /usr/lib/arm-linux-gnueabi directory. There is libbluetooth.a, libbluetooth.so, libbluetooth.so.3 and libbluetooth.so.3.12.0 files. Do I need to add all those files to my Eclipse linker or is that .a file just necessary?
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
Ok I figured it out by myself. Just needed libbluetooth.a and libbluetooth.so files and also add -lbluetooth flag for the linker.
Re: Bluetooth C programming
Some background info for you....lihakimpale wrote:Ok I figured it out by myself. Just needed libbluetooth.a and libbluetooth.so files and also add -lbluetooth flag for the linker.
.a versions are static libraries.
.so versions are dynamic link libraries.
If you link against a static library the required code from the library will end up in your executable.
If you link against a dynamic library the required code from the library will be added to your program by the linker/loader at run time.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
Do you know what is the problem when I try to get connection between L2CAP_client.c and L2CAP_server.c it gives error: "Connection refused". I have hard-coded the bluetooth address so it should be right.
Re: Bluetooth C programming
Make sure that the client device is both paired and trusted
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
Of course it ain't working:Douglas6 wrote:Make sure that the client device is both paired and trusted
- pi@raspberrypi ~ $ sudo bluez-simple-agent hci0 00:15:83:32:7A:3F
RequestPinCode (/org/bluez/1880/hci0/dev_00_15_83_32_7A_3F)
Enter PIN Code: 0000
Creating device failed: org.bluez.Error.AuthenticationRejected: Authentication Rejected
- pi@raspberrypi ~ $ sudo bluez-test-device trusted 00:15:83:32:7A:3F
Traceback (most recent call last):
File "/usr/bin/bluez-test-device", line 158, in <module>
path = adapter.FindDevice(args[1])
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.bluez.Error.DoesNotExist: Does Not Exist
Re: Bluetooth C programming
Ok, you'll need to get it paired before you can trust it, and before you can connect to it.
What type of Bluetooth device is it? Does it perhaps have a different pin code than "0000"? The only way I can reproduce your "Authentication Rejected" error when pairing my phone is to enter an incorrect pin code ( or pressing 'cancel') when the phone asks me for it. If it's not a phone, then try pin code "1234", the 'other' default.
What type of Bluetooth device is it? Does it perhaps have a different pin code than "0000"? The only way I can reproduce your "Authentication Rejected" error when pairing my phone is to enter an incorrect pin code ( or pressing 'cancel') when the phone asks me for it. If it's not a phone, then try pin code "1234", the 'other' default.
Last edited by Douglas6 on Tue Jul 29, 2014 6:20 pm, edited 1 time in total.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
These both are B-speech bluetooth USB adapters. I tried with PIN 1234 but it gives me the same error, I tried to pair with my phone and it paired without problems,Douglas6 wrote:Ok, you'll need to get it paired before you can trust it, and before you can connect to it.
What type of Bluetooth device is it? Does it perhaps have a different pin code than "0000"? The only way I can reproduce your "Authentication Rejected" error when pairing my phone is to enter an incorrect pin code when the phone asks me for it. If it's not a phone, then try pin code "1234", the 'other' default.
Re: Bluetooth C programming
Ok, what are they plugged into? I assume one is a Pi. Is the other also a Pi? If so, try runninglihakimpale wrote:These both are B-speech bluetooth USB adapters
Code: Select all
sudo bluez-simple-agent
Code: Select all
sudo bluez-simple-agent hci0 00:15:83:32:7A:3F
Back on Pi 'A', it should be prompting you for a pin code. Enter the same one. enter 'yes' to the next prompt (if it responds with 'Cancel', try it again. Should work on the first or second try.)
Then use the command you used before for trusting, from Pi 'B'.
If the other device is not a Pi, but a PC, the procedure should be similar. You need agents running on both computers to handle pairing. In this case it will be easier to initiate pairing from the PC.
Last edited by Douglas6 on Tue Jul 29, 2014 6:45 pm, edited 1 time in total.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
I also tried this which should solve the problem: "Patch the /usr/bin/bluez-simple-agent script. Replace "KeyboardDisplay" with "DisplayYesNo"."
It didn't solve for me.
It didn't solve for me.
-
- Posts: 80
- Joined: Tue Jul 22, 2014 4:12 pm
Re: Bluetooth C programming
Yes I have two Pis and got it working now. Thank you very much for your help!Douglas6 wrote:Ok, what are they plugged into? I assume one is a Pi. Is the other also a Pi? If so, try runninglihakimpale wrote:These both are B-speech bluetooth USB adapterson Pi 'A'. Then on Pi 'B' run yourCode: Select all
sudo bluez-simple-agent
and enter a pin code.Code: Select all
sudo bluez-simple-agent hci0 00:15:83:32:7A:3F
Back on Pi 'A', it should be prompting you for a pin code. Enter the same one. enter 'yes' to the next prompt (if it responds with 'Cancel', try it again. Should work on the first or second try.)
Then use the command you used before for trusting, from Pi 'B'.
If the other device is not a Pi, but a PC, the procedure should be similar. You need agents running on both computers to handle pairing. In this case it will be easier to initiate pairing from the PC.
Re: Bluetooth C programming
Great, glad to hear it.lihakimpale wrote:Yes I have two Pis and got it working now. Thank you very much for your help!
Nope. As you've seen, you still need agents running, if only to reply 'Yes'. If using a serial bluetooth module, for example, it will have firmware running an agent. By the way, there's no need to patch bluez-simple-agent; it will take a command-line argument, e.g. '-c DisplayYesNo'.lihakimpale wrote:I also tried this which should solve the problem: "Patch the /usr/bin/bluez-simple-agent script. Replace "KeyboardDisplay" with "DisplayYesNo"."