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

I have a libreelec device, which can run docker, but can’t install additional software like git.

My main reason to put everything in a container, is that it can easily move between different hosts.

No that should not be normal!

What is that client that is trying to connect?

Do you have more than one device? Is the MQTT clientID different on each one? I have seen similar problems when I happened to be using the same MQTT ClientID from 2 machines to the same broker (not with Monitor though) although it does look like the ID is unique.

If you set the MQTT ClientID when the client creates the connection, it creates a ‘persistent’ session so the broker (should) picks up with the client where it left off after a disconnect/reconnect.

unfortunately not, my building I own I just own up to the walls, and its straight onto a road, which has some passing traffic, and a lot of people walking past it, they use it as a cut through to the town, so motion sensors outside would be going off probably more than the default scans :frowning:

Sure, and libreelec doesn’t even run bash, it uses another shell (ash I think). So even adding the script (which you can do) wouldn’t be guaranteed to work. Have you tried that?

I think docker wouldn’t be hard to set up for this, although I am no expert. The difficulty may ba docker access to bluetooth.

BTW I am a team member for libreelec and kodi.

Cheers.

For info. I’ve tried running monitor in ‘trigger only on depart’ mode and it sadly does nothing to cut down on the interference which is affecting my Particle Cores. The Photons (better on board WiFi chip) seem not to be affected at all…so I’m minded to drop yet more cash on replacing the Cores with Photons. Just want to be sure the Photons don’t mind the scanning before potentially wasting £50 on three Photons that aren’t otherwise needed!

I first need to have a docker container to be able to focus on the bluetooth part, but there are some threads how say it’s possible.

just read this thread and immediately bought a pi zero… nice work @andrewjfreyer!

I’ve read the github page several times but still don’t get it how to config monitor to be in “permanent scan mode”.

for now I use only one pi for one room and want immediate notifications if I leave or come back (maybe scan every 10 seconds for changes?)… i thought that bash monitor.sh -ra would do that?

sadly if I start monitor with bluetooth disabled on my phone it scans once and after that never again…

Could someone point me in the right direction on how to configure it that way?

Thanks

1 Like

Thanks so much for your help! I have only tried your settings one day but it seems to be working now.

2 Likes

So not sure if this is of any help to my interference problem, but I live across the road from a block of 13 flats, and also another 8/9 behind my house, the road in front is also used as a cut through to town, so there is basically a lot of bluetooth devices around. Watching my log for the last 40 mins, it seems to be picking up a load of things. If I remember correctly, doesn’t it start an arrival scan when it detects a new device to it ? So all these random devices passing me are going to cause it to keep scanning ? Hence the interference ?

I have no idea really what I am talking about, but here is the log from the last 40 mins if it helps anyone.

https://pastebin.com/raw/2VvBJGfd

Hi guys. This project sounds amazing. However, I just skimped through more than 300 messages in this thread and I couldn’t find any info about Mi Band 3.

Before I invest my money and time into this, may I confirm does this work with Xiaomi Mi Band 3 fitness tracker?

In the docker container I’m working on I got it all working, but it need some tweaking before getting official, think I will have the time this weekend

1 Like

I would try this
preference: random advertisement expiration = 135

also you need to see how many of the devices around you are static and add them to the ignore file so these dont count as “random Advertisements”

It honestly just sounds like you have too many devices near you. Also since you have your friends bluetooth devices in the configuration it is essentially going to scan forever…

1 Like

2 things. this is not going to be good for ROOM level events because this method works relatively far… Unless your house is just that big.

also I think you are looking for
sudo bash monitor.sh -r -a

This should do periodic scans instead of random advertisement scans.

My detection is now near perfect thanks for the hints @benjimatt! I have one final ‘issue’ I use my device tracker statuses (x2 of them) as a trigger in a couple of automations when the state changes to ‘home’.

The problem is on some occasions when leaving these automations are fired a few times presumably due to the device tracker state bouncing between not_home/home before settling on not_home. Has anybody experienced similar and overcome it? I have a few possible solutions but can’t help but think there is a simple one I’m missing.

A possible solution would be to toggle an input boolean on the first not_home status, delay and toggle back then use this as a condition in the automations. Ideally though id like to deal with the root cause if possible.

Thank you for the suggestions @benjimatt I do realise I am in a overly heavily populated area, so a bit of a special case.

Obviously when I only have my MAC address in, its fine, it just when I add in a few more MAC address’s it’s when the interference happens. Just been sitting here watching everything tick over for a while and pondering.

Excuse my lack of knowledge of how bluetooth works, but from what I can gather,

When monitor receives a ping from a bluetooth device, it starts a scan to see if it’s in it’s know devices, and then if it is, it marks it as here. if not, its just finishes the scan, and then sit’s there and wait’s till it get’s another ping from another bluetooth device.

Correct me if I am wrong.

It seems to know what that device’s MAC that triggered the scan is from the log,

0.1.675 07:15:04 pm [CMD-RAND]  79:34:32:44:CC:E8 ADV_NONCONN_IND -75 dBm
0.1.675 07:15:04 pm [CMD-INFO]  **** Started arrival scan. [x2 max rep] ****

but then obviously when scanning, its sending out a bluetooth packet ? to try and get a response ? Which is when the interference happens for me, and then obviously, the more MAC’s I add in, the more packet’s being sent out to check if that MAC that triggered the scan is here ?

If I use the ignore file to ignore MAC’s they then won’t trigger a scan when they are detected ?

Is there no way for monitor to just ignore all MAC address’s apart from mine, and my friends ?

As I said, it seems to know what the MAC trigger the scan is, so can it not just use that value to parse through the known MAC address’s file, and then if its is one of the 5 MAC address’s in the file, it then starts the scan ?

The random advertisements starting a scan seems a bit weird for me, they are random MAC’s, so should be ignored in my case. I think I read somewhere in the doc’s about it being for beacon’s or something, but not too sure if I am making that bit up.

Again, any help or advice from anyone is super appreciated.

Def not a programmer but for me this sounds like a good idea if possible. Only the mac addreses in the known addresses list trigger a scan. Possible, have no clue. Hope it is

yup I know exactly what you mean. There are two ways in my opinion.

If you are using a depart scan on a trigger then you should not have an issue. So if you used a door sensor to trigger a depart scan it will only trigger when the door opens or closes (just the depart scan)

so this way once you are home you will stay HOME until the depart trigger (door) is triggered again. This was needed for me because my GF like to turn her phone off or let it die. SO this way she isnt seen as NOT HOME because my trigger never started a depart scan

ha ha if only it were that easy.

FYI the only time your phone sends out its ACTUAL MAC ADDRESS is if you are in pairing mode I think. SO right now if I went to your house and did a scan while you were home I would get random apple Bluetooth advertisements that are coming off of your phone. So to me its just a random Bluetooth phone giving of the signal. Its not until you actually call the mac address that the cell phone will give its name.

So unfortunately you cant just wait for a advertisement from certain cell phone because it gives a random bluetooth addresses instead of its actual mac address each time.

beacons do give their actual mac address though so these are handles differently.

this is why I say blacklist all of the STATIC macs that you are getting so at least you can stop getting scans from these devices. Furthermore how is your tablet connected. is it using 2.4ghz or 5 ghz?

2 Likes

I just finished my docker container for monitor, if anyone would like to try it out please feel free.

https://hub.docker.com/r/bloody2k/rpi_monitor/

4 Likes

@phdelodder