diff --git a/README.md b/README.md index 9ae66ca0..544a6cd4 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -92,13 +92,13 @@ 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 ``` -
Monitor Setup +
Monitor and Bluetooth-Proximity Setup -## Setup `monitor` +## Setup `monitor and bluetooth-proximity` 1. Clone `monitor` git: ```bash @@ -106,8 +106,16 @@ sudo apt-get install -f libmosquitto-dev mosquitto mosquitto-clients libmosquitt 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/ diff --git a/monitor.sh b/monitor.sh index db35f337..e22e118c 100755 --- a/monitor.sh +++ b/monitor.sh @@ -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 \ diff --git a/rssi.py b/rssi.py new file mode 100644 index 00000000..c49090cf --- /dev/null +++ b/rssi.py @@ -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 [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()