andrewjfreyer / presence Goto Github PK
View Code? Open in Web Editor NEWDistributed poll-based BTLE presence detection reported via mqtt
Distributed poll-based BTLE presence detection reported via mqtt
Can we use this for tracking Apple Watch BLE?
When presence is running for awhile, if then stops reporting confidence. Always zero until I reboot which then fixes it.
My behavior_preferences
file is this:
#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN AWAY FROM HOME
delay_between_owner_scans_away=6
#DELAY BETWEEN SCANS OF OWNER DEVICES WHEN HOME
delay_between_owner_scans_present=20
#HOW MANY VERIFICATIONS ARE REQUIRED TO DETERMINE A DEVICE IS AWAY
verification_of_away_loop_size=6
#HOW LONG TO DELAY BETWEEN VERIFICATIONS THAT A DEVICE IS AWAY
verification_of_away_loop_delay=3
#PREFERRED HCI DEVICE
hci_device='hci0'
If i then check the status using systemctl
, I get network errors:
pi@pi-presence:~/presence $ sudo systemctl status presence.service
● presence.service - Presence service
Loaded: loaded (/etc/systemd/system/presence.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-07-15 19:37:57 BST; 27min ago
Main PID: 229 (bash)
CGroup: /system.slice/presence.service
├─ 229 /bin/bash /home/pi/presence/presence.sh &
├─4450 /bin/bash /home/pi/presence/presence.sh &
├─4451 /bin/bash /home/pi/presence/presence.sh &
├─4452 hcitool -i hci0 name 38:53:9C:9A:BC:02
├─4453 grep -v not available
└─4454 grep -vE hcitool|timeout|invalid|error
Jul 15 19:47:18 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:47:20 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:18 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:26 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:27 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:29 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:29 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:55:38 pi-presence bash[229]: Error: Network is unreachable
Jul 15 19:56:09 pi-presence bash[229]: Error: Network is unreachable
Jul 15 20:00:25 pi-presence bash[229]: Error: Network is unreachable
If I then restart, I seem to get back into a good state:
pi@pi-presence:~/presence $ sudo systemctl status presence.service
● presence.service - Presence service
Loaded: loaded (/etc/systemd/system/presence.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-07-15 20:05:29 BST; 3s ago
Main PID: 4513 (bash)
CGroup: /system.slice/presence.service
├─4513 /bin/bash /home/pi/presence/presence.sh &
├─4526 /bin/bash /home/pi/presence/presence.sh &
├─4527 /bin/bash /home/pi/presence/presence.sh &
├─4528 hcitool -i hci0 name 3C:28:6D:1D:8E:66
├─4529 grep -v not available
└─4530 grep -vE hcitool|timeout|invalid|error
Jul 15 20:05:29 pi-presence systemd[1]: Started Presence service.```
This might be unrelated but trying to figure out why it will suddenly stop detecting devices.
0.4.11
False entry events are triggered
Unknown
Hello and thank you for this great project. I'm working on setting it up on an RPi3, but I'm having an issue related to installing the newer bluez version.
make
works fine. Then I run sudo make install
, which appears to complete without errors:
pi@MyPi:~/bluez-5.49 $ sudo make install
make --no-print-directory install-am
/bin/mkdir -p '/usr/lib'
/bin/bash ./libtool --mode=install /usr/bin/install -c lib/libbluetooth.la '/usr/lib'
libtool: install: /usr/bin/install -c lib/.libs/libbluetooth.so.3.18.16 /usr/lib/libbluetooth.so.3.18.16
libtool: install: (cd /usr/lib && { ln -s -f libbluetooth.so.3.18.16 libbluetooth.so.3 || { rm -f libbluetooth.so.3 && ln -s libbluetooth.so.3.18.16 libbluetooth.so.3; }; })
libtool: install: (cd /usr/lib && { ln -s -f libbluetooth.so.3.18.16 libbluetooth.so || { rm -f libbluetooth.so && ln -s libbluetooth.so.3.18.16 libbluetooth.so; }; })
libtool: install: /usr/bin/install -c lib/.libs/libbluetooth.lai /usr/lib/libbluetooth.la
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/mkdir -p '/usr/bin'
/bin/bash ./libtool --mode=install /usr/bin/install -c client/bluetoothctl monitor/btmon tools/rctest tools/l2test tools/l2ping tools/bccmd tools/bluemoon tools/hex2hcd tools/mpris-proxy tools/btattach '/usr/bin'
libtool: install: /usr/bin/install -c client/bluetoothctl /usr/bin/bluetoothctl
libtool: install: /usr/bin/install -c monitor/btmon /usr/bin/btmon
libtool: install: /usr/bin/install -c tools/rctest /usr/bin/rctest
libtool: install: /usr/bin/install -c tools/l2test /usr/bin/l2test
libtool: install: /usr/bin/install -c tools/l2ping /usr/bin/l2ping
libtool: install: /usr/bin/install -c tools/bccmd /usr/bin/bccmd
libtool: install: /usr/bin/install -c tools/bluemoon /usr/bin/bluemoon
libtool: install: /usr/bin/install -c tools/hex2hcd /usr/bin/hex2hcd
libtool: install: /usr/bin/install -c tools/mpris-proxy /usr/bin/mpris-proxy
libtool: install: /usr/bin/install -c tools/btattach /usr/bin/btattach
/bin/mkdir -p '/usr/libexec/bluetooth'
/bin/bash ./libtool --mode=install /usr/bin/install -c src/bluetoothd obexd/src/obexd '/usr/libexec/bluetooth'
libtool: install: /usr/bin/install -c src/bluetoothd /usr/libexec/bluetooth/bluetoothd
libtool: install: /usr/bin/install -c obexd/src/obexd /usr/libexec/bluetooth/obexd
/bin/mkdir -p '/usr/lib/cups/backend'
/bin/bash ./libtool --mode=install /usr/bin/install -c profiles/cups/bluetooth '/usr/lib/cups/backend'
libtool: install: /usr/bin/install -c profiles/cups/bluetooth /usr/lib/cups/backend/bluetooth
/bin/mkdir -p '/etc/dbus-1/system.d'
/usr/bin/install -c -m 644 src/bluetooth.conf '/etc/dbus-1/system.d'
/bin/mkdir -p '/usr/include/bluetooth'
/usr/bin/install -c -m 644 lib/bluetooth.h lib/hci.h lib/hci_lib.h lib/sco.h lib/l2cap.h lib/sdp.h lib/sdp_lib.h lib/rfcomm.h lib/bnep.h lib/cmtp.h lib/hidp.h '/usr/include/bluetooth'
/bin/mkdir -p '/usr/share/man/man1'
/usr/bin/install -c -m 644 tools/rctest.1 tools/l2ping.1 tools/bccmd.1 tools/btattach.1 tools/hid2hci.1 '/usr/share/man/man1'
/bin/mkdir -p '/usr/share/man/man8'
/usr/bin/install -c -m 644 src/bluetoothd.8 '/usr/share/man/man8'
/bin/mkdir -p '/usr/lib/pkgconfig'
/usr/bin/install -c -m 644 lib/bluez.pc '/usr/lib/pkgconfig'
/bin/mkdir -p '/lib/udev/rules.d'
/usr/bin/install -c -m 644 tools/97-hid2hci.rules '/lib/udev/rules.d'
/bin/mkdir -p '/lib/udev'
/bin/bash ./libtool --mode=install /usr/bin/install -c tools/hid2hci '/lib/udev'
libtool: install: /usr/bin/install -c tools/hid2hci /lib/udev/hid2hci
Then I run sudo apt-get update
and sudo apt-get upgrade -y
, which doesn't install or update anything.
There's no bluetoothd
in my path at this point, but it does exist in src/bluetoothd
:
pi@MyPi:~/bluez-5.49 $ which bluetoothd
pi@MyPi:~/bluez-5.49 $ bluetoothd -v
-bash: bluetoothd: command not found
pi@MyPi:~/bluez-5.49 $ src/bluetoothd -v
5.49
Then I run sudo apt-get install pi-bluetooth
, but instead of being given the option to skip bluez installation during setup, an older version of bluez (5.43) is forced on me (only one file conflicts):
pi@MyPi:~ $ sudo apt-get install pi-bluetooth
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
bluez
Suggested packages:
pulseaudio-module-bluetooth
The following NEW packages will be installed:
bluez pi-bluetooth
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/725 kB of archives.
After this operation, 3,467 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package bluez.
(Reading database ... 73012 files and directories currently installed.)
Preparing to unpack .../bluez_5.43-2+rpt2+deb9u2_armhf.deb ...
Unpacking bluez (5.43-2+rpt2+deb9u2) ...
Selecting previously unselected package pi-bluetooth.
Preparing to unpack .../pi-bluetooth_0.1.7_all.deb ...
Unpacking pi-bluetooth (0.1.7) ...
Processing triggers for systemd (232-25+deb9u2) ...
Processing triggers for man-db (2.7.6.1-2) ...
Processing triggers for dbus (1.10.26-0+deb9u1) ...
Setting up bluez (5.43-2+rpt2+deb9u2) ...
Configuration file '/etc/dbus-1/system.d/bluetooth.conf'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** bluetooth.conf (Y/I/N/O/D/Z) [default=N] ? n
Created symlink /etc/systemd/system/dbus-org.bluez.service → /lib/systemd/system/bluetooth.service.
Created symlink /etc/systemd/system/bluetooth.target.wants/bluetooth.service → /lib/systemd/system/bluetooth.service.
Setting up pi-bluetooth (0.1.7) ...
Created symlink /etc/systemd/system/multi-user.target.wants/hciuart.service → /lib/systemd/system/hciuart.service.
Processing triggers for dbus (1.10.26-0+deb9u1) ...
Processing triggers for systemd (232-25+deb9u2) ...
Once I go through with installation and allow sudo apt-get install pi-bluetooth
to install bluez, I end up with an older version of bluez:
pi@MyPi:~ $ bluetoothd -v
5.43
I saw one other mention of a similar issue in the HA discussion forum, but they were able to resolve it by trying again. I've run through the steps 3 times now with the same result each time.
I've tried rebooting, running make
multiple times, sudo make install
multiple times, etc. Do you have any suggestions on things to try? I'm hoping I'm doing something dumb... In the meantime I will continue with the older version of bluez.
Thanks again!
hi,
[ENABLE SSH] Create blank file, without any extension, in the root, in. How do you understand this step?
After the SD card is written to the IMG file, it is re inserted on the PC. In the boot partition, root directory is found.
Is there a mode at all that would let me search continuously for all devices without predefining them and receiving the id and name of the device on the mqtt topic?
Hi, I'm using your solution with succes on 4 raspberry pui 0.
Sometimes my PI need a reboot, but when it restarts, the presence script evidence a presence "on" also if before the presence was "off". of course after some seconds the presence is set again "off".
Is it possible modify the script to avoid this?
Thanks
Guido
Love your work. Building this tonight to test as like you, tried everything else. Now I know this is left field but hear me out. I see quite a few HA users (myself included) moving away from Pi's and into either Intel NUC's or Docker (me both) leaving us without bluetooth support or at least not easily.
I was going to deploy another Pi3 just for the purpose of bluetooth tracking my plant sensors then connect this to my main HA instance using MQTT Eventstream; one on each floor.
Then I came across your solution on the HA forums so I though goly, wouldn't it be great if this could do that too. You have both bluetooth tracking, WiFi and MQTT so here is my official feature request. Feel free to laugh :)
While this is an incredibly awesome script I do have a hard time to use these MQTT messages in openHAB because of the colons in topic.
OpenHAB uses colons in MQTT binding and so mac addresses with lots of colons don’t work:
Item myItem {mqtt="[:::], [:::], ..."}
Would be great if there would be an option to change the topic title to not use colons or just bring that piece of information into payload.
Over time, the amount of mosquitto_sub processes continues to grow. This hammers the mosquitto broker, with its logs showing a bunch of PINGREQ and PINGRESP messages.
2018-06-18T18:44:43.050523971Z 1529347483: Sending PINGRESP to mosqsub|17759-Beacon2
2018-06-18T18:44:43.050587044Z 1529347483: Received PINGREQ from mosqsub|18451-Beacon2
2018-06-18T18:44:43.050647668Z 1529347483: Sending PINGRESP to mosqsub|18451-Beacon2
2018-06-18T18:44:43.050708761Z 1529347483: Received PINGREQ from mosqsub|20206-Beacon2
2018-06-18T18:44:43.050765635Z 1529347483: Sending PINGRESP to mosqsub|20206-Beacon2
2018-06-18T18:44:43.050821989Z 1529347483: Received PINGREQ from mosqsub|20548-Beacon2
2018-06-18T18:44:43.050880582Z 1529347483: Sending PINGRESP to mosqsub|20548-Beacon2
2018-06-18T18:44:43.050936675Z 1529347483: Received PINGREQ from mosqsub|20736-Beacon2
2018-06-18T18:44:43.050994071Z 1529347483: Sending PINGRESP to mosqsub|20736-Beacon2
2018-06-18T18:44:43.581670083Z 1529347483: Received PINGREQ from mosqsub|21844-Beacon2
2018-06-18T18:44:43.582061173Z 1529347483: Sending PINGRESP to mosqsub|21844-Beacon2
2018-06-18T18:44:43.583568814Z 1529347483: Received PINGREQ from mosqsub|6840-Beacon2
2018-06-18T18:44:43.583715219Z 1529347483: Sending PINGRESP to mosqsub|6840-Beacon2
2018-06-18T18:44:43.784707727Z 1529347483: Received PINGREQ from mosqsub|6493-Beacon2
2018-06-18T18:44:43.785003870Z 1529347483: Sending PINGRESP to mosqsub|6493-Beacon2
2018-06-18T18:44:43.785106108Z 1529347483: Received PINGREQ from mosqsub|16358-Beacon2
2018-06-18T18:44:43.785203191Z 1529347483: Sending PINGRESP to mosqsub|16358-Beacon2
2018-06-18T18:44:43.785301315Z 1529347483: Received PINGREQ from mosqsub|20910-Beacon2
2018-06-18T18:44:43.785400324Z 1529347483: Sending PINGRESP to mosqsub|20910-Beacon2
2018-06-18T18:44:43.858785575Z 1529347483: Received PINGREQ from mosqsub|17412-Beacon2
2018-06-18T18:44:43.859020364Z 1529347483: Sending PINGRESP to mosqsub|17412-Beacon2
2018-06-18T18:44:43.859403850Z 1529347483: Received PINGREQ from mosqsub|21083-Beacon2
When scanning rapidly, bluetooth and wifi interference is possible.
Hello, i installed all the packeges and the RPI is working and accessable via ssh, i added my BT mac addresses and fired up the system but i dont get topics with the addresses, the mqtt log showing that the device keep connecting with the username and passwords but disconnect right after.1587456234: New client connected from 192.168.1.25 as mosq-idMm4T4OJZS0Hdq7El (p2, c1, k60, u'user').
1587456234: Client mosq-idMm4T4OJZS0Hdq7El disconnected.
I'm a bit confused as to what the difference between Presence and Monitor is. Might be worth adding into the README?
Last will messages not sending from broker when presence service is stopped.
location/pi_zero_location/00:00:00:00:00:00 , as I think openhab not able to read topic name with:
in owner_devices, you set as "00:00:00:00:00:00 #My-Phone", can the mac address be assign on second part? My_Phone as below
location/pi_zero_location/My_Phone
Thank you for this awesome piece of work. I'm looking into rolling it out with a Pi in each room, but would like to be able to differentiate in which room a person is. I recall mentioned somewhere, you might look at the possibility of including RSSI in the JSON payload. Is this still on the cards?
I have a older version of Bluez running on my device.
root@ubuntu:~# bluetoothd -v
5.37
How do I update this to a newer version.
I followed the instructions on how to install a new bluez version and then downloaded and installed bluez v 5.50.
But it seems that my system still uses older version of bluez. How do i delete the older version or specify to use new version?
I followed the steps of installation from:
https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation
Note that I'm not using raspberry pi. I'm using linux inside a container.
My device name is hci1 because I have an external bt device and my internal device does not work...
I have a MiBand 3 Xiaomi and i want to use it with your program but i have this issue:location/owner/habitacion1/EC:89:64:02:CC:54 {"confidence":"0","name":"Invalid device: No such device","scan_duration_ms":"5071","timestamp":"Sun Sep 09 2018 08:52:17 GMT+0200 (CEST)"}
.
in my mqtt i have this:
mqtt_address="my broker" mqtt_port="1883" mqtt_user="myuser" mqtt_password="mypassword" mqtt_topicpath="location" mqtt_room="habitacion1"
and in my owner_devices i have:
EC:89:64:02:CC:54 #mywatch
in Hassio sensor i have:
- platform: mqtt state_topic: 'location/owner/habitacion1/EC:89:64:02:CC:54' value_template: '{{ value_json.confidence }}' unit_of_measurement: '%' name: 'Habitacion'
but my sensor.habitacion he still 0% and i was in my room with my watch.
Can you help me plz? sorry for my language.i leave in spain.
0.4.11
Names of devices from cache are incorrectly reported
Unknown
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.