[presence] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection

Hi @andrewjfreyer this is excellent both functionality and the documentation! Thank you sir!

I set this up last yesterday with on two Pi Zeros with 2 iPhones and 2 Tiles. Everything worked excellent when bench testing. Came to real life today and both my Zeros seem to have stopped sending messages.

My “Upstairs” Zero remained all devices at 50% and stopped sending any messages.

My “Downstairs” Zero remained all devices at 100% and stopped sending any messages.

When I arrived home and rebooted both Zeros using a terminal they both sprang back into action! I’m unsure where logs if they exist are located? I’m reluctant to set a cron job to reboot as thats a dirty fix. Anybody know what might have gone /be going wrong?

Update the script again - over the past holiday weekend I took some time to update the script and pushed a huge number of updates out. I’m lazy and push debug changes to my github so that all my nodes can update on their own, sorry… :frowning:

Yes, that’s the process. If you installed via a git clone, you can navigate to the monitor directory again and run git pull to update.

Run manually the first time to detect/correct errors.

If you setup monitor to run via systemctl, then it’ll run at start. Else, its manual.

I mean that the two scripts are vying for exclusive use of the bluetooth hardware. They may well succeed operating at the same time, but there’s really no point and the behavior cannot be guaranteed.

No, not really. Variability in RSSI is far too great for reliable distance measurements. We can get close, but nowhere I’d consider “reliable”

I’m not seeing any changes for presence, just monitor on your github.

There doesn’t seem to be an update available for presence, git is showing the last commit as 18days ago. Your other project monitor has had an update should I now be using monitor apposed to presence?

EDIT: Just waited home for the wife to leave and everything remained reporting 100%. After a reboot of both Pis her iPhone slowly dropped down to 0% on both shortly followed by her Tile keyring.

@apt are you experiencing the same issue?

Not seeing any issues with the current release of presence. Works as expected. Hoping the new changes to monitor filter down to presence soon.

Might I suggest introducing a develop > master git branching model? That way you could locally work on and check out the develop branch on your local nodes and let them auto update. Then, when you are happy with your script you could do a merge to the master branch.

Thank you again for the amount of spare time that you are putting in to this project!

Updated to the latest monitor script, it reports the RSSI if my Mi Band but still doesn’t track it, also getting these errors for my phone;

monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is ":00:00:00:5A:AD")
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is ":00:00:00:5A:AD")

Log;

pi@raspberrypi:~/monitor $ sudo bash monitor.sh -r -b -a -u

Starting monitor.sh (v. 0.1.543)…

repeated scan mode enabled
beacon scan mode enabled
report all scan results mode enabled
updating monitor.service
monitor.service updated with arguments: -r -b -a
preference: delay between scans = 3
preference: periodic arrive/depart check interval = 15
preference: periodic arrive interval = 45
preference: periodic depart interval = 90
preference: database refresh interval = 35
preference: max arrival scan attempts = 2
preference: max depart scan attempts = 4
preference: random advertisement expiration = 45
preference: beacon rssi change required for reporting = 5
0.1.543 10:01:37 am location/scan
0.1.543 10:01:37 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:01:37 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:01:45 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD arrived?
0.1.543 10:01:47 am location/owner/6C_Pi_Zero/00:00:00:00:5A:AD { retain: false, version : 0.1.543, confidence : 100, name : Oneplus One, timestamp : Tue Sep 04 2018 10:01:47 GMT+0100 (BST), manufacturer : XEROX CORPORATION , type : PUBLIC_MAC }
0.1.543 10:01:47 am location/scan/arrive
0.1.543 10:01:47 am [CMD-NAME] 00:00:00:00:5A:AD OnePlus One XEROX CORPORATION
0.1.543 10:01:49 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:01:52 am location/scan
0.1.543 10:01:54 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:01:54 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:01:57 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:01:58 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:01:58 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:01:58 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:02:07 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:02:13 am location/scan
0.1.543 10:02:13 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:02:13 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:02:21 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:02:22 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:02:30 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:02:31 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:02:31 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:02:31 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:02:37 am location/scan
0.1.543 10:02:37 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:02:37 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:02:46 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:02:52 am location/scan
0.1.543 10:02:52 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:02:52 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:03:01 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:03:11 am location/scan
0.1.543 10:03:11 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:03:11 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:03:20 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:03:22 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:03:28 am location/scan
0.1.543 10:03:28 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:03:28 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:03:36 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:03:37 am location/scan
0.1.543 10:03:39 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:03:39 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:03:43 am location/scan
0.1.543 10:03:47 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:03:47 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:03:56 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:03:58 am location/scan
0.1.543 10:03:59 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:03:59 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:04:04 am [CMD-SCAN] (No. 3) C8:0F:10:69:44:6B arrived?
0.1.543 10:04:12 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:04:13 am [CMD-SCAN] (No. 4) C8:0F:10:69:44:6B arrived?
0.1.543 10:04:13 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:04:21 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:04:22 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:04:22 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:04:22 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:04:28 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:04:37 am [CMD-RSSI] C8:0F:10:69:44:6B Mi Band 1s PUBL RSSI: -78 dBm (Moderate Motion Approaching) (x2)
0.1.543 10:04:37 am location/scan
0.1.543 10:04:37 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:04:37 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:04:43 am location/scan
0.1.543 10:04:43 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:04:43 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:04:46 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:04:56 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:04:58 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:04:59 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:04:59 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:05:00 am location/scan/depart
0.1.543 10:05:00 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:05:13 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x3)
0.1.543 10:05:23 am location/scan
0.1.543 10:05:23 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:05:23 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:05:31 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:05:40 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:05:40 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:05:40 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:05:41 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:05:43 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:05:58 am location/scan
0.1.543 10:05:58 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:05:58 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:06:07 am location/scan
0.1.543 10:06:07 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:06:07 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:06:16 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:06:24 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:06:25 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:06:25 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:06:26 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:06:28 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:06:37 am location/scan
0.1.543 10:06:37 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:06:37 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:06:43 am location/scan
0.1.543 10:06:43 am [CMD-INFO] **** Started group scan. [x2 max rep] ****
0.1.543 10:06:43 am [CMD-SCAN] (No. 1) C8:0F:10:69:44:6B arrived?
0.1.543 10:06:52 am [CMD-SCAN] (No. 2) C8:0F:10:69:44:6B arrived?
0.1.543 10:06:52 am location/scan
0.1.543 10:06:57 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:06:57 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 292: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:07:00 am [CMD-INFO] **** Completed scan. ****
0.1.543 10:07:01 am location/owner/6C_Pi_Zero/C8:0F:10:69:44:6B { retain: false, version : 0.1.543, confidence : 0, name : Mi Band 1s, timestamp : Tue Sep 04 2018 10:07:01 GMT+0100 (BST), manufacturer : Unknown , type : PUBLIC_MAC }
0.1.543 10:07:01 am [CMD-NAME] C8:0F:10:69:44:6B Mi Band 1s Unknown
0.1.543 10:07:27 am [CMD-RSSI] C8:0F:10:69:44:6B Mi Band 1s PUBL RSSI: -98 dBm (Moderate Motion Departing) (x2)
0.1.543 10:07:52 am location/scan
0.1.543 10:07:52 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:07:53 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:07:59 am location/scan
0.1.543 10:07:59 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:07:59 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:08:07 am location/scan
0.1.543 10:08:08 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:08:08 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:08:28 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x3)
0.1.543 10:08:38 am location/scan
0.1.543 10:08:38 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:08:38 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:08:52 am location/scan
0.1.543 10:08:53 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:08:53 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:08:58 am location/scan
0.1.543 10:08:58 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:08:58 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:09:07 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:09:13 am location/scan
0.1.543 10:09:13 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:09:13 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:09:28 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x2)
0.1.543 10:09:37 am location/scan
0.1.543 10:09:38 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:09:38 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:09:58 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x3)
0.1.543 10:10:08 am location/scan
0.1.543 10:10:08 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:10:08 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:10:13 am location/scan
0.1.543 10:10:14 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:10:14 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:10:23 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:10:28 am location/scan
0.1.543 10:10:29 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:10:29 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:10:38 am location/scan
0.1.543 10:10:38 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:10:38 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:10:59 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x3)
0.1.543 10:11:08 am location/scan
0.1.543 10:11:08 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:11:08 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:11:14 am [CMD-INFO] **** Rejected group scan. No devices in desired state. ****
0.1.543 10:11:15 am [CMD-RSSI] C8:0F:10:69:44:6B Mi Band 1s PUBL RSSI: -71 dBm (Fast Motion Approaching) (x2)
0.1.543 10:11:28 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x2)
0.1.543 10:11:38 am location/scan
0.1.543 10:11:38 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:11:38 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:11:46 am location/scan
0.1.543 10:11:46 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:11:46 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
0.1.543 10:11:54 am [CMD-RSSI] C8:0F:10:69:44:6B Mi Band 1s PUBL RSSI: -87 dBm (Moderate Motion Departing)
0.1.543 10:11:54 am location/scan
0.1.543 10:11:54 am [CMD-RSSI] C8:0F:10:69:44:6B Mi Band 1s PUBL RSSI: -87 dBm (Moderate Motion Departing)
0.1.543 10:11:54 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:11:55 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:12:02 am location/scan
0.1.543 10:12:03 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:12:03 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)
0.1.543 10:12:23 am [CMD-INFO] **** Rejected group scan. No devices in desired state. **** (x2)
0.1.543 10:12:28 am location/scan
0.1.543 10:12:29 am [CMD-INFO] **** Started group scan. [x4 max rep] ****
0.1.543 10:12:29 am [CMD-SCAN] (No. 1) 00:00:00:00:5A:AD departed?
monitor.sh: line 307: 00:00:00:00:5A:AD: syntax error in expression (error token is “:00:00:00:5A:AD”)

1 Like

Rodger that

Fell over again this evening think I’m going to remove the Tiles and see if it works any better.

1 Like

Yes there’s a bug that I’m working out.

1 Like

I may have addressed the issue with a quick fix. Please let me know if you continue to experience this.

I take it it’s just Monitor that’s seen the update?

1 Like

Yes. Once monitor is stable again, it should be suitable for every installation of presence.

Hello Andrew,
Great project! Thank you for sharing with us.
My Gear s3 or the MiBand2 is tracked. No mqtt message posted to location/owner/#. I just have updated to the latest version.

Sorry please update again - I pushed quite a few changes and bug fixes for monitor out today. If you are using presence, these bands will not be detected unless they conform to the iBeacon protocol.

Hi!

I’ve spent the better part of the weekend and the last few days updating the beacon detection. Please let me know if the -g flag works for you to detect this as a generic beacon.

So when monitor is stable we can see a new update to presence?

1 Like