I'm running on YOCTO and I've done a simple sw with only hci_get_route() so to understand how it work.
Before run the application I've activate the bluetooth:
systemctl enable bluetooth.service
systemctl start bluetooth.service
and check the status with
systemctl status bluetooth.service
and the response is "running", so I run the application but
hci_get_route
return a bad id and errno is "no such device". I'm forgetting something?
Thanks
below the commands to activate the BT interface via command line :
brcm_patchram_plus --patchram /etc/firmware/BCM43430A1.1DX.hcd --enable_hci --no2bytes --tosleep 50000 --baudrate 1000000 --use_baudrate_for_download /dev/ttyUSB0 & hciconfig -a
hciattach /dev/ttyUSB0 any
hciconfig hci0 up
after this 3 steps hcitool dev show the bt interface and the call at hci_get_route works. The step 1 is not necessary after hw reboot, you need only to execute step 2 & 3
Related
I try to understand how btmgmt work. I search command equal to:
sudo hciconfig -a hci0 lm master
I have try to use sudo btmon for dumping hci command but I have only this result:
# RAW Open: hciconfig (privileged) version...
with no op-code output, this not realy help me. Writing output to btsnoop format reveal some unknown op codes (btmon -a /tmp/btsnoop). With wireshark I have no HCI events, I don't understand.
Using sudo strace hciconfig... reveal socket and ioctl call with ioctl(ctl, HCISETLINKMODE, dr)
I read HCISETLINKMODE value and hciconfig function
but nothing about op-code to put the interface in MASTER or SLAVE mode. For some others btmgmt commands I use btmon output and the command op-code and I use op-code to search in mgmt-api.txt.
After reading that hciconfig would be deprecated, I'm trying to migrate commands using btmgmt and i just miss this one.
Any help is welcome. Thank you
what I want to achieve in a test setup is:
running:
hcitool -i hci0 lescan --duplicates --passive
on one shell
and in parallel connect on another via
hcitool -i hci0 lecc <BTADDR>
The moment I issue the connect command the scan process exits.
Why is that? I thought choosing to scan --passive will allow a scan output while managing a connection?
Best,
If you are on kernel 3.2 and above use gatttool or bluetoothctl for LE connections. hcitool is deprecated and you should not be using them anymore. Compile and install latest bluez and use gatttool for LE connections. If your LE device is in the vicinity, you should be able to connect, read and write using gatttool directly:
say, your local BT adapter is hci0 and the remote device BD_ADDR is 12:22:33:44:55:66 then:
gatttool -i hci0 -b 12:22:33:44:55:66 -I
[12:22:33:44:55:66][LE]>connect
Attempting to connect to 12:22:33:44:55:66
Connection successful
[12:22:33:44:55:66][LE]>characteristics
Read manual and help to know more about gattool.
When I run this command which makes the ble device scanning for just 5 seconds only:
$ sudo timeout 5s hcitool -i hci0 lescan
the output is shown in the terminal screen.
But when I redirect the output to a file to save the addresses of the advertising devices, every time I run the command I find the file is empty and the output isn't visible in the terminal nor in the file.
The command I used:
$ sudo timeout 5s hcitool -i hci0 lescan > file.txt
What do I have to do in order to make hcitool correctly redirect its ouput to the file?
timeout by default sends a SIGTERM to the program. Looks like hcitool doesn't handle that gracefully. Instead use SIGINT (equivalent to ctrl-c).
sudo timeout -s SIGINT 5s hcitool -i hci0 lescan > file.txt
Recently got a Blend Micro for a project and I need a raspberry pi to initiate a bluetooth connection with it.
For that I installed BlueZ 5.2 on raspberry and i used this command to detect the Blend Micro :
sudo hcitool -i hci0 lescan
I correctly detect the Blend micro then i use the gatttool command :
sudo gatttool -i hcitool hci0 -b XX:XX:XX:XX:XX:XX -I
(where the XX corresponds to the Blend MAC address)
But when I initiate the connection by typing connect it says "Host is down" :
$ sudo gatttool -i hci0 -b XX:XX:XX:XX:XX:XX -I
[ ][XX:XX:XX:XX:XX:XX][LE]> connect
Connecting... connect error: Host is down (112)
[ ][XX:XX:XX:XX:XX:XX][LE]>
Do you have any idea on how to fix that ? Tried many things without any results though...
Regards, RaZZeR
When you are connecting, you need to add "-t random" to your command line.
I have a script that initializes my bluetooth setup on an Intel Edison. It allows pairing and connecting to this headless machine running Yocto Poky Linux. It was suggested that I put the startup script in /etc/init.d and run update-rc.d myscript.sh defaults. The script ran but it didn't work (generated boot errors saying bluetooth device not found) because Bluetooth had not started yet. I did some reasearch and after removing my links I did update-rc.d myscript.sh defaults 99 which was claimed to run the script last but it did't make any differrence -- it still ran in the same place in the boot sequence. I verified that the links had S99 on them so it seemed like they were set up correctly. There is another post on SO asking a similar question but that was a Ubuntu system where mine is Poky Linux. That solution suggested putting the startup script in a directory that does not exist on my system. There were other suggestions, putting it in rc.local, which I did and got the same result, it runs before Bluetooth is initialized.
Here is my script. My program is called nmea_thread and is run last. Everything else is initializing Bluetooth.
#!/bin/sh
/usr/sbin/rfkill unblock bluetooth
/usr/bin/hciconfig hci0 up
/usr/bin/hciconfig hci0 piscan
/usr/bin/hciconfig hic0 sspmode 0
/home/root/simpleAgent/simple-agent &
/home/root/nmea_thread
Often bluetooth is initialized asynchronously, so you can't be sure that your script will be run after hci0 is added. Good solution is to wait for BT initialization in background:
#!/bin/bash
if [ "$1" != "background" ]; then
$0 background &
else
#Wait until BT is initialized
for ((i = 0; i <= 100; i++)) do
hciconfig hci0 && break
usleep 100000
done
/usr/sbin/rfkill unblock bluetooth
/usr/bin/hciconfig hci0 up
/usr/bin/hciconfig hci0 piscan
/usr/bin/hciconfig hic0 sspmode 0
/home/root/simpleAgent/simple-agent &
/home/root/nmea_thread
fi
hciattach is the correct way.
syntax
hciattach /dev/ttyAMA0 bcm43xx 3000000
you need to flash the driver first before initializing it. Currently i don't remember how, but thats how i made it with raspberry pi and yocto.
Note if you use systemV, you can do call it from a script and it will work
Using SystemD, you need to make it in a service and wait. Falshing should be done in the two cases.