Linux Bluetooth l2ping with signal strength (without connecting?)
Asked Answered
P

3

5

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.

Porterhouse answered 2/10, 2011 at 19:46 Comment(0)
A
6

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

Auriga answered 3/10, 2011 at 15:48 Comment(4)
thanks for the link and the idea, but this needs the devices to be in discoverable mode which they don't necessarily will be. I know the bd_addr of all devices I want to ping/measure, that's why I started out with l2ping where there is no need for the targets to be in discoverable mode.Porterhouse
In that case, you can use hcitool (part of BlueZ stack). hcitool. If you do 'hcitool cc' that creates a connection without encryption/authentication, then you can monitor rssi using 'hcitool rssi'. The only problem is some devices may no let the connection stay active if you don't authenticate (pair).Auriga
yeah, that works. of the two devices I tried so far both allowed the (unpaired) connection to exist so that I could check rssi/lq. So this is a working solution, but just in case anyone knows of a way without connecting and without the target(s) being discoverable, I'd still love to see that.Porterhouse
The link to the source appears to be dead.Farad
I
5

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
Ibert answered 11/5, 2017 at 16:30 Comment(0)
S
1

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

Sonni answered 18/9, 2019 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.