lennard743
Posts: 3
Joined: Mon Aug 26, 2019 6:37 pm
Location: Berlin

Bluetooth RSSI

Tue Aug 27, 2019 12:50 pm

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

PhatFil
Posts: 1373
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Bluetooth RSSI

Tue Aug 27, 2019 3:17 pm

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.

User avatar
Douglas6
Posts: 4770
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth RSSI

Tue Aug 27, 2019 6:22 pm

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.

lennard743
Posts: 3
Joined: Mon Aug 26, 2019 6:37 pm
Location: Berlin

Re: Bluetooth RSSI

Wed Aug 28, 2019 2:19 pm

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?

User avatar
Douglas6
Posts: 4770
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth RSSI

Wed Aug 28, 2019 2:39 pm

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.

lennard743
Posts: 3
Joined: Mon Aug 26, 2019 6:37 pm
Location: Berlin

Re: Bluetooth RSSI

Wed Aug 28, 2019 6:44 pm

Okay now i undertstood :D Thank you. So but how can i just scan the RSSI of XX:XX:XX:XX:XX:XX ?

User avatar
Douglas6
Posts: 4770
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Bluetooth RSSI

Wed Aug 28, 2019 7:05 pm

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 

Return to “Python”