Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev python bluez #295

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sudo reboot
5. Install Bluetooth Firmware, if necessary:
```bash
#install Bluetooth drivers for Pi Zero W
sudo apt-get install pi-bluetooth
sudo apt-get install pi-bluetooth bluetooth python-bluez

```

Expand All @@ -92,22 +92,30 @@ sudo wget http://repo.mosquitto.org/debian/mosquitto-buster.list
#update caches and install
apt-cache search mosquitto
sudo apt-get update
sudo apt-get install -f libmosquitto-dev mosquitto mosquitto-clients libmosquitto1
sudo apt-get install -f libmosquitto-dev mosquitto mosquitto-clients libmosquitto1
```
</details>

<details><summary><i>Monitor Setup</i></summary>
<details><summary><i>Monitor and Bluetooth-Proximity Setup</i></summary>

## Setup `monitor`
## Setup `monitor and bluetooth-proximity`

1. Clone `monitor` git:
```bash
#install git
cd ~
sudo apt-get install git

#clone this repo
#install Python setuptools
sudo apt-get install python3-setuptools

#clone monitor and bluetooth-proximity repo
git clone git://github.com/andrewjfreyer/monitor
git clone https://github.com/ewenchou/bluetooth-proximity.git

#install bluetooth-proximity
cd bluetooth-proximity
sudo python3 setup.py install

#enter `monitor` directory
cd monitor/
Copy link

@jlo88 jlo88 Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd monitor/
cd ../monitor/

Expand Down
16 changes: 2 additions & 14 deletions monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,8 @@ connectable_present_devices () {

#CREATE CONNECTION AND DETERMINE RSSI
#AVERAGE OVER THREE CYCLES; IF BLANK GIVE VALUE OF 100
known_device_rssi=$(counter=0; \
avg_total=0; \
hcitool cc "$known_addr"; \
avg_total=""; \
for i in 1 2 3; \
do scan_result=$(hcitool rssi "$known_addr" 2>&1); \
scan_result=${scan_result//[^0-9]/}; \
scan_result=${scan_result:-99}; \
[[ "$scan_result" == "0" ]] && scan_result=99; \
counter=$((counter+1)); \
avg_total=$((avg_total + scan_result )); \
sleep 0.5; \
done; \
printf "%s" "$(( avg_total / counter ))")
known_device_rssi=$(python3 rssi.py "$known_addr" 3)


#PUBLISH MESSAGE TO RSSI SENSOR
publish_rssi_message \
Expand Down
36 changes: 36 additions & 0 deletions rssi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

from bt_proximity import BluetoothRSSI
import time
import sys

BT_ADDR = '' # You can put your Bluetooth address here
NUM_LOOP = 1
rssilist = []

def print_usage():
print(
"Usage: python rssi.py <bluetooth-address> [number-of-requests]")


def main():
if len(sys.argv) > 1:
addr = sys.argv[1]
elif BT_ADDR:
addr = BT_ADDR
else:
print_usage()
return
if len(sys.argv) == 3:
num = int(sys.argv[2])
else:
num = NUM_LOOP
btrssi = BluetoothRSSI(addr=addr)
for i in range(0, num):
rssi = btrssi.request_rssi()
rssilist.append(99) if rssi == None else rssilist.append(abs(int(rssi[0])))
time.sleep(1)
print(min(rssilist))


if __name__ == '__main__':
main()