Bluetooth LE Signal Strength Linux

2019-02-02 01:44发布

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 exsist but would be fairly easy to write

Thank You

5条回答
贼婆χ
2楼-- · 2019-02-02 02:01

Ok sorry for the other answer...

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

查看更多
聊天终结者
3楼-- · 2019-02-02 02:02

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.

I hope this helps.

查看更多
家丑人穷心不美
4楼-- · 2019-02-02 02:03

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

查看更多
爷的心禁止访问
5楼-- · 2019-02-02 02:10

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

查看更多
做自己的国王
6楼-- · 2019-02-02 02:19

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

查看更多
登录 后发表回答