Linux Bluetooth l2ping with signal strength (without connecting?)

我的未来我决定 提交于 2020-01-03 15:09:44

问题


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 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.


回答1:


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




回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/7628758/linux-bluetooth-l2ping-with-signal-strength-without-connecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!