开发者

Linux Bluetooth l2ping with signal strength (without connecting?)

For any Linux BlueZ/BT experts here:

I'm looking for a way to "ping" known BT devices (known BDADDR) and if they are in range I'd like to know the approximate signal strength.

I know that I could first run l2ping, then establish开发者_Python百科 a connection to the device and finally check the rssi or link quality if the connection worked without pairing first.

However what I'm looking for is a way of getting the signal strength without connecting to the device first. Perfect would be a signal strength measurement from the l2ping reply packet, but I don't know if that info is available at all and passed along the stack.


You can obtain RSSI during inquiry scan, without connecting to devices. Here's an example using pybluez. You could also do the same thing directly from C using Bluez on linux.

inquiry-with-rssi.py


I'm using this code with my iPhone 7 and Raspberry Pi and it works great.

#!/bin/bash

sudo hcitool cc AA:BB:CC:DD:EE:FF 2> /dev/null

while true
do
    bt=$(hcitool rssi AA:BB:CC:DD:EE:FF 2> /dev/null)
    if [ "$bt" == "" ]; then
        sudo hcitool cc AA:BB:CC:DD:EE:FF  2> /dev/null
        bt=$(hcitool rssi AA:BB:CC:DD:EE:FF 2> /dev/null)
    fi

    echo "$bt"
done


Very old question, but someone might be still interested in.

The previous answers talk about the RSSI during an inquiry scan. It's correct but not always doable, i.e. undiscoverable devices. For this class of devices you can establish a connection and eventually ask for the connection RSSI. Connection RSSI can be obtained using BlueZ command hcitool rssi <MAC:ADDRESS>. Blend l2ping and hcitool rssi do the trick. For this reason, I created this repository: [https://github.com/edoardesd/myBluez] Output: 44 bytes from XX:XX:XX:XX:XX:XX id 8 time 8.23ms with RSSI -9

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜