Page 1 of 1

Bluetooth RSSI

Posted: Tue Aug 27, 2019 12:50 pm
by lennard743
Hello,
I want to do a small project with my Raspberry Pi Zero W. First step (the device should be connected before and trusted) (oh and in Python) to scan for Bluetooth devices. Then, if a known Bluetooth device is within range, connect the Raspberry to the device via BLE. Then scanning (in a loop) RSSI and depending on the strength of the signal something should happen. Unfortunately, I'm not familiar with Bluetooth at all. Anyone with any help or advise would be appreciated :)

Lennard

Re: Bluetooth RSSI

Posted: Tue Aug 27, 2019 3:17 pm
by PhatFil
its on my todo list, but i found existing projects to simply copy to access the sensors i use.. But i have the following bookmarked for later digestion..
http://www.raspberry-pi-geek.com/Archiv ... (offset)/1

Hope its a useful starting point.

Re: Bluetooth RSSI

Posted: Tue Aug 27, 2019 6:22 pm
by Douglas6
Should be pretty simple using the bluepy Python library. First, install bluepy (https://github.com/IanHarvey/bluepy).

The following code will scan for ten seconds, and then print the RSSI for all BLE devices it found:

Code: Select all

from bluepy.btle import Scanner
 
scanner = Scanner()
devices = scanner.scan(10.0)
 
for device in devices:
    print("DEV = {} RSSI = {}".format(device.addr, device.rssi))
You'll need to run it with 'sudo', not sure why.

Re: Bluetooth RSSI

Posted: Wed Aug 28, 2019 2:19 pm
by lennard743
Ah okay thank you for the links and the code. @douglas6 if the scans finds a device which is trusted, then the raspberry should connect to the device via ble... Do you know how to do that and then it would be cool to just output the RSSI of the connected device, is that possible?

Re: Bluetooth RSSI

Posted: Wed Aug 28, 2019 2:39 pm
by Douglas6
Bluepy will allow you to connect with a BLE device.

You should probably research BLE. 'Paired' and 'trusted' are classic Bluetooth terms that have no real relevance with BLE.

Re: Bluetooth RSSI

Posted: Wed Aug 28, 2019 6:44 pm
by lennard743
Okay now i undertstood :D Thank you. So but how can i just scan the RSSI of XX:XX:XX:XX:XX:XX ?

Re: Bluetooth RSSI

Posted: Wed Aug 28, 2019 7:05 pm
by Douglas6

Code: Select all

from bluepy.btle import Scanner
 
scanner = Scanner()
devices = scanner.scan(10.0)
 
for device in devices:
    if device.addr == "XX:XX:XX:XX:XX:XX" :
        # Do something 

Re: Bluetooth RSSI

Posted: Tue Feb 18, 2020 10:49 am
by TommasoLovergine96
Hi everyone,
running the code you posted i get this error:

Code: Select all

sintax error: "(" unexpected 
at "scanner=Scanner()" line.

Can anybody help me?

Thanks,
regards, Tommaso Lovegine

Re: Bluetooth RSSI

Posted: Wed Feb 19, 2020 4:59 pm
by Douglas6
Did you install Bluepy for the version of Python you are using?

Re: Bluetooth RSSI

Posted: Sun May 10, 2020 5:56 pm
by SleepeeZzz
Hi all for some reason whenever I do this exactly, after installing everything and followings all of the steps it says no module called bluepy found

Re: Bluetooth RSSI

Posted: Thu May 21, 2020 10:14 am
by hippy
SleepeeZzz wrote:
Sun May 10, 2020 5:56 pm
Hi all for some reason whenever I do this exactly, after installing everything and followings all of the steps it says no module called bluepy found
As per above ...
Douglas6 wrote:
Wed Feb 19, 2020 4:59 pm
Did you install Bluepy for the version of Python you are using?
Depending on the Python version being used, as per https://github.com/IanHarvey/bluepy ...

sudo pip install bluepy
sudo pip3 install bluepy