Bluetooth LE Signal Strength Linux
Asked Answered
G

8

20

Hello is there any way to get the signal strength of near by bluetooth le devises in linux? Or any good libraries for nodejs, php or mono (I do know some c++ or python but would prefer to say away from them) if a tool does not exisst but would be fairly easy to write.

Guidon answered 25/6, 2014 at 19:31 Comment(0)
E
38

On Linux, the way to do this is with the hcitool command. However, you have to be connected to get the rssi of a device. If you want to achieve this from the command line, try:

#hcitool rssi AA:BB:CC:DD:EE:FF

If you want to see the actual C code to achieve this, take a look at the bluez tools/hcitool.c file, under the cmd_rssi function.

static void cmd_rssi(int dev_id, int argc, char **argv)
{
    ...
}

For Bluetooth Low Energy, I only know one way to do this, and that is using the #btmon command. Run btmon in the background then scan for Bluetooth Low Energy devices:

#./btmon &
# hcitool lescan

The results displayed on the monitor should be similar to this:

> HCI Event: LE Meta Event (0x3e) plen 12                                                                                  
      LE Advertising Report (0x02)
        Num reports: 1
        Event type: Scan response - SCAN_RSP (0x04)
        Address type: Public (0x00)
        Address: AA:BB:CC:DD:EE:FF (<Vendor Name>)
        Data length: 0
        ***RSSI: -34 dBm (0xde)***
AA:BB:CC:DD:EE:FF <Device Name>

Note that when using btmon you do not have to connect to get the rssi of a BLE device.

Ezraezri answered 25/6, 2014 at 20:7 Comment(5)
hcitool rssi Seems to only be for regular bluetooth not bluetooth le, I get "Get connection info failed: No such file or directory" when I try even when connected ( for bluetooth le you connect by hcitool lecc [MAC] not the regular hcitool cc [MAC],Guidon
Tagged the question with bluetooth-lowenergy because I missed the le part :) Have you tried #hcidump? I've read that you can use it to read rssi value of Low Energy devices but I have no devices with me to test that.Ezraezri
Edited the question to include the Bluetooth Low Energy part. I tried #hcidump and it didn't work for me, but #btmon worked just fine.Ezraezri
What is the meaning of "plen 12" in the first line of BLE scan " > HCI Event: LE Meta Event (0x3e) plen 12" ?Dennis
If BLE devices are connected, you can't find RSSI with this way.Spectrohelioscope
S
10

No need to connect when using btmgmt

$ sudo btmgmt find

Discovery started
hci0 type 7 discovering on
hci0 dev_found: 50:8C:FD:99:0A:EC type LE Random rssi -80 flags 0x0000 
AD flags 0x06 
eir_len 23
…

The relative signal strength indicator is rssi -80, but the list is much longer containing more information about this and other devices.

To spy on your Bluetooth neighbourhood showing only unique MAC addresses with their strongest RSSI, run the following command:

$ sudo btmgmt find |grep rssi |sort -n |uniq -w 33

hci0 dev_found: 40:43:42:B3:71:11 type LE Random rssi -53 flags 0x0000 
hci0 dev_found: 44:DA:5F:EA:C6:CF type LE Random rssi -78 flags 0x0000 
hci0 dev_found: 7F:7D:08:6B:E0:37 type LE Random rssi -74 flags 0x0000 
hci0 dev_found: A4:58:0F:21:A1:8C type BR/EDR rssi -79 flags 0x0000
Socorrosocotra answered 10/6, 2019 at 7:55 Comment(0)
F
5

You can use a combination of:

sudo hcitool lescan --duplicates & ;
sudo hcidump --raw 

that will provide you the raw dump of all the bluetooth packets which contain all relevant information you must be interested in such as : UUID, Major, Minor, RSSI, TxPower. You will have to run some kind of script to parse and filter LE packets and make them into readable form.

One of the scripts written with Bash and S editor was provided by jjnebaker here with the problem and solution discussed here

The Other option is to use PyBluez using the example code here But you might find the solution provided by Switchdoc labs useful according to your needs as well. here

Flicker answered 31/7, 2014 at 14:29 Comment(0)
S
3

This works for c language, but has an error when casting the bytes that have the information about de rssi signal. https://github.com/glock45/intel-edison-playground/blob/master/scan.c

this line 121:

printf("%s - RSSI %d\n", addr, (**char**)info->data[info->length]);

should be:

printf("%s - RSSI %d\n", addr, (**int8_t**)info->data[info->length]);

I found these by looking inside bluez-version/monitor/*.c, where btmon program is. You can see the data types and structs, hcidump.c is very useful and packets.c, and main.c too, but there are many to learn about the hci sockets.

Singe answered 21/5, 2015 at 18:51 Comment(1)
Fastest scanner I found. Tested on Linux Mint with gcc 5.5.0 on Asus dongle (connected to PC) and it reads fine with cast to "(char)".Neary
G
2

I also found a program I was able to edit to do what I wanted as well I through it up on my github account https://github.com/tholum/bluez/blob/master/blue.py

Guidon answered 29/6, 2014 at 13:57 Comment(0)
T
2

i found several solutions, but most were too slow for my needs to use as a tracking function.

check out https://github.com/abandonware/noble containing some examples.

my standalone scanner is also based on abandonware's module and can be found here: https://github.com/efeuentertainment/BLE-continuous-RSSI-scan

node index.js BLEMAC

continuously lists the RSSI with an update frequency of about 2 per second / depending on BLE device.

also fast updates based on bash is:

sudo hcitool lescan --duplicates &

combined with one of the following lines: continuous updates

sudo hcidump | grep "E6:4E:57:09:74:E4" -A 4
sudo btmon | grep "E6:4E:57:09:74:E4" -A 7

only the next received update

sudo hcidump | grep -m 1 "E6:4E:57:09:74:E4" -A 4 | grep "RSSI"
sudo btmon | grep -m 1 "E6:4E:57:09:74:E4" -A 7 | grep "RSSI"

hope that helps. it's an old thread but my search engine lead me here anyway.

Trueblue answered 5/7, 2020 at 19:2 Comment(0)
S
0

try :

$ bluez-test-discovery

output :

[ 18:7A:93:05:E4:B1 ]
    Name = AMIYJ_E4B1
    Paired = 0
    LegacyPairing = 0
    Alias = AMIYJ_E4B1
    Broadcaster = 0
    UUIDs = dbus.Array([dbus.String(u'0000fff0-0000-1000-8000-00805f9b34fb')], signature=dbus.Signature('s'), variant_level=1)
    Address = 18:7A:93:05:E4:B1
    RSSI = -65
    Class = 0x000000

gives you : RSSI = -65

Subaquatic answered 15/11, 2016 at 13:45 Comment(0)
M
0

For connected devices you can use btmgmt conn-info

e.g.

$ sudo btmgmt conn-info -t 2 E4:0C:E6:59:B6:FC
Connection Information for E4:0C:E6:59:B6:FC (LE Random)
    RSSI -78    TX power 0  maximum TX power 0

(You have the code for that command at https://github.com/bluez/bluez/blob/150bbff449c787f26b7de3e6006bdb2ea6365b08/tools/btmgmt.c#L3984-L4030 ).

I think you may also be able to use BlueZ's DBus RSSI property of the org.bluez.Device1 interface :

        int16 RSSI [readonly, optional]

            Received Signal Strength Indicator of the remote
            device (inquiry or advertising).

but that didn't work for me:

$ dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_E4_0C_E6_59_B6_FC org.freedesktop.DBus.Properties.Get string:"org.bluez.Device1" string:"RSSI"
Error org.freedesktop.DBus.Error.InvalidArgs: No such property 'RSSI'

Maybe because the property is optional. Some other properties did work for me:

$ dbus-send --print-reply=literal --system --dest=org.bluez /org/bluez/hci0/dev_E4_0C_E6_59_B6_FC org.freedesktop.DBus.Properties.Get string:"org.bluez.Device1" string:"Name"
   variant       eono BTC 01
Maddis answered 2/10, 2022 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.