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

Normal error when the bluetooth hardware is asked to do too much. Do this:

sudo hciconfig hci0 down
sudo hciconfig hci0 up

Then run the scan command again.

I’ve just noticed this and I’m really excited to try this. To see if I can start running monitor again.

did you figure out how to get the Apple Watch to work?
Mine wont whatever i try.

I tried going into the settings and using the MAC address that is listed there, but no luck. Neither when i run with -b do i get anything from the watch.
Any ideas @andrewjfreyer?

I have had no difficulty tracking my Apple Watches (Series 0 & Series 4) by adding the bluetooth mac address to the known static addresses file.

Make sure you’re using the bluetooth mac address - the Wifi mac address is different.

Spot on :smile: :+1:
The LE Scan worked great after the down / up.

I spotted one of the tokens in the btmon window

HCI Event: LE Meta Event (0x3e) plen 43 [hci0] 1592.623477
LE Advertising Report (0x02)
Num reports: 1
Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
Address type: Random (0x01)
Address: F0:AD:ED:20:5F:8B (Static)
Data length: 31
Flags: 0x04
BR/EDR Not Supported
Company: Apple, Inc. (76)
Type: iBeacon (2)
UUID: 23f54d63-b5e7-3798-c847-a27083d0efeb
Version: 48252.55283
TX power: -128 dB
RSSI: -70 dBm (0xba)

The UUID mangling you mentioned is super confusing!
Anyway, that is my token with UUID
EBEFD083-70A2-47C8-9837-E7B5634DF523
as far as I can tell.

Here is another.

HCI Event: LE Meta Event (0x3e) plen 43 [hci0] 2659.513536
LE Advertising Report (0x02)
Num reports: 1
Event type: Non connectable undirected - ADV_NONCONN_IND (0x03)
Address type: Random (0x01)
Address: FD:5A:BC:7C:DD:F3 (Static)
Data length: 31
Flags: 0x04
BR/EDR Not Supported
Company: Apple, Inc. (76)
Type: iBeacon (2)
UUID: 21f54d63-b5e7-3798-c847-a27083d0efeb
Version: 48252.54771
TX power: -53 dB
RSSI: -58 dBm (0xc6)

So looking good so far. Do I need to check anything else?

Thanks very much again

That all looks good. monitor should be picking this guy up. Do you have any filters set? Do you have anything in the known_beacon_addresses file or the known_static_addresses file?

Thanks.
I have my iPhone and iPad in the known_static_addresses file. They are recognised fine. I have HomeAssistant states working for them.

I have tried one of the token’s MAC addresses in the known_beacon_addresses file like this
CD:8B:DA:C4:24:A8 Bike

That entry doesn’t seem to come up in monitor though, or the MAC addresses of the other tokens. Nor do I ever see any UUIDs popping up. :confused:

I have not created any filters. I left all the settings as default.

preference: using default mqtt protocol version
preference: minimum time between the same type of scan = 15
preference: regex filter for flags to accept = .*
preference: regex filter for flags to reject = NONE
preference: regex filter for manufacturers to accept = .*
preference: regex filter for manufacturers to reject = NONE
preference: maximum sequential arrive scan attempts = 1
preference: maximum sequential depart scan attempts = 2
preference: selected HCI device = hci0
mqtt trigger: monitor/scan/ARRIVE
mqtt trigger: monitor/scan/DEPART

Thanks again!

try putting this address in the known_beacon_addresses file: FD:5A:BC:7C:DD:F3

Ok, done. known_beacon_addresses is as follows

CD:8B:DA:C4:24:A8 Yellow
FD:5A:BC:7C:DD:F3 White

(The colours are of the beacons.)

Restarted monitor.sh
The beacons are showing up :+1:
So I think I’m good to go. Thanks very much again.

Is it simple to explain why the UUID doesn’t show up as expected?

Ps if there is a beer fund then please dm me a PayPal address :slight_smile:

No beer fund, but I really appreciate the thought. :slight_smile:

A second thing that you can do that would be helpful for me to debug why this particular beacon doesn’t work would be to run an hcidump and DM me the results.

To do this, run the same two shells as before, one with lescan and one with btmon. In a third shell, run:

sudo hcidump -raw

You’ll get a lot of hexidecimal output. Instead of trying to parse that yourself, please just dump the whole thing in a DM, stopping the LE scan once you see your iBeacon in btmon.

Does that make sense?

1 Like

Hello @andrewjfreyer,
I can’t get the trigger scans working. I send a empty message to monitor/scan/arrive or monitor/scan/depart and nothing appears in the log.
I correcty receive the message if I use mosquitto_sub. I am assuming I should always see “something” in the log when a scan is triggered?

Yes, you’ll see a note in the log when an mqtt message is received.

I started it with -tad and receive [INSTRUCT] mqtt trigger arrive , but it seems these are random and even if not they appear very delayed. What could this be?

That’s the log entry, yes.

Monitor takes anywhere from 10 - 30 seconds to “settle” down on a first run. This is because it is consuming and processing data from the bluetooth environment. This time will increase if you’re running on a low-power device such as a pi zero w, and/or if you are in a high-traffic area with a number of devices around you (large apartment building).

Wait for maybe 30 seconds or so after launching via command line, then try sending an MQTT instruction.

Remember - if all your known devices are “home”, an arrival scan will not be performed, even if triggered by MQTT. There’s no point to scanning for devices that we know to be home. Similarly, if any device is known to be “away”, a depart scan will not be performed, even if triggered by MQTT.

1 Like

thanks for the reply. I see one xyz-123 Apple Inc device once in a while, but other than that only my two devices that I added to known_static_addresses, so I’m guessing traffic isn’t a problem. Monitor is running on a Raspberry Pi without anything else running…

Should the [INSTRUCT] message always appear?
Should the [INSTRUCT] messages be near instant (after settle down?)

Yep, I’m trying that but I get an error

pi@raspberrypi:~/monitor $ sudo hcidump -raw
HCI sniffer - Bluetooth packet analyzer ver 5.43
Can't open dump file: No such file or directory

Sorry. This looks like it’s easy to fix but what I know about Raspbian is basically what is in your setup guide on the subject.

Btw, and FYI, I just updated to the latest beta.

Yes, they should be very soon in time. The only other factor would be if your broker is particularly hammered with topics from other services.

Sorry, typo on my part. Need two dashes before raw:

sudo hcidump --raw

I am using the embedded homeassistant broker, without any other services, so that can’t be a problem. I am using a bluetooth dongle. Can that make a difference?

Yes! Another user reported a similar slowdown when using a dongle. The reason was that his dongle was not actually ignoring duplicate advertisements. Monitor relies on this to reduce the size of the firehose of data is has to digest.

To test to make sure that this is in fact the issue, open up:

sudo hcitool lescan

If you see this run wild (i.e., not stop after say 15 - 20 seconds), then we have definitely identified your issue.