My issue is pretty simple to explain: I doing some tests with my Raspberry and Bluetooth Low Energy (BLE). I bought a Bluetooth 4.0 dongle and everything is setup fine. Now for a little project, I need to retrieve the RSSI value from a beacon that is advertising nearby (guess for what purpose). The way I found to do so is a simple pipeline: sudo hcidump -a | grep rssi | awk '{print $2}' Making it being preceded from sudo hcitool lescan &> /dev/null makes the trick: I get printed at screen continuously the RSSI of the beacon nearby. And that is the problem: continuously. I would like to be able to manipulate this value within a shell script or a python script. The most simple result I can be happy with is to create a csv file with the time stamp and the RSSI value

I hope to have explained clearly ;)

  • Do you have any sample output? Appending | head -1 to the end could do it (to get the first line)...
    – Wilf
    Jun 5, 2014 at 23:03

1 Answer 1


This worked for me:

  1. As you pointed out, first run the hcitool in the background: sudo hcitool lescan --duplicates Note the use of "duplicates" so we keep on logging the changing RSSI value of the BLE device

  2. Create a script (tester.sh) and insert the following code:

    while read address
        read RSSI
        echo "$timestamp,$address,$RSSI"

in the above we're basically waiting for to lines from stdin (that's the 'read' lines). The first line containing 'read' is the MAC address of the device, the second 'read' line is to get the RSSI value. I also inserted the timestamp just for a more comprehensive answer

  1. Now we use bash pipes to feed in the information we need like so:

    sudo hcidump -a | egrep 'RSSI|bdaddr' | cut -f 8 -d ' ' | ./tester.sh > /tmp/result.csv

All we're doing here is using HCIDUMP, then egrep to filter out the lines containing the device address and the RSSI. The output of the egrep command is prepended with a tab, so in the subsequent cut command we have to use the 8th field to get what we're after since i'm separating on ' '. Last we feed this into our script which processes the values and output them in csv format. I then just redirect the output into the csv file

To manipulate the RSSI value you just need to modify the tester.sh file as needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.