Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan bluetooth low energy using hcitool?

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?

like image 243
ahmed ayman Avatar asked Jan 08 '23 16:01

ahmed ayman


1 Answers

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

like image 189
kaylum Avatar answered Jan 10 '23 05:01

kaylum