andrewjfreyer / monitor

Distributed advertisement-based BTLE presence detection reported via mqtt
1.67k stars 194 forks source link

Confidence goes from 100 to 0 and seldomly stays to 100 #237

Closed Nihvel closed 4 years ago

Nihvel commented 5 years ago

Hi Andrew, I've been playing around with Monitor for some months now. I believe I'm confident enough to know how it works but I am not sure if this that I show you is a bug or it's me to be the idiot (:

The log as soon as monitor is restarted:

Sep 04 18:36:00 pihole-00 systemd[1]: Started Monitor Service.
-- Subject: Unit monitor.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit monitor.service has finished starting up.
--
-- The start-up result is RESULT.
Sep 04 18:36:00 pihole-00 bash[23969]: ===================================================
Sep 04 18:36:00 pihole-00 bash[23969]:               *** BETA/DEV BRANCH ***
Sep 04 18:36:00 pihole-00 bash[23969]: ===================================================
Sep 04 18:36:00 pihole-00 bash[23969]: > starting monitor.sh (v. 0.2.197)...
Sep 04 18:36:00 pihole-00 bash[23969]: > removing web request caches
Sep 04 18:36:04 pihole-00 bash[23969]: > C1:E9:4D:54:A0:61 confidence topic: monitor/pihole/C1:E9:4D:54:A0:61 (has not previously connected to hci0)
Sep 04 18:36:04 pihole-00 bash[23969]: > C0:B8:98:9C:2C:A9 confidence topic: monitor/pihole/C0:B8:98:9C:2C:A9 (has not previously connected to hci0)
**Sep 04 18:36:06 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:06 PM [CMD-PUBL]        C0:B8:98:9C:2C:A9 Mi Band 3 Anhui Huami Information Technology Co., Ltd. -70 dBm
Sep 04 18:36:46 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:46 PM [CMD-MQTT]        monitor/pihole/C0:B8:98:9C:2C:A9 { ... confidence : 100 ... }**
Sep 04 18:36:46 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:46 PM [CMD-MQTT]        monitor/pihole/C1:E9:4D:54:A0:61 { ... confidence : 0 ... }
Sep 04 18:36:46 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:46 PM [CMD-PUBL]        **C1:E9:4D:54:A0:61 juri_mi4 Anhui Huami Information Technology Co., Ltd. -79 dBm
Sep 04 18:36:46 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:46 PM [CMD-MQTT]        monitor/pihole/C1:E9:4D:54:A0:61 { ... confidence : 100 ... }**
Sep 04 18:36:50 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:50 PM [CMD-RSSI]        PUBL 28:11:A5:E6:CD:4C RSSI: -84 dBm (initial reading | 116 dBm)
Sep 04 18:36:50 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:50 PM [CMD-PUBL]        28:11:A5:E6:CD:4C  SGL Italia S.r.l. for Bose Corporation -84 dBm
Sep 04 18:36:50 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:50 PM [CMD-MQTT]        monitor/pihole/28:11:A5:E6:CD:4C { ... confidence : 100 ... }
**Sep 04 18:36:52 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:52 PM [CMD-MQTT]        monitor/pihole/C1:E9:4D:54:A0:61 { ... confidence : 0 ... }
Sep 04 18:36:52 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:52 PM [CMD-NAME]        C1:E9:4D:54:A0:61 Mi Smart Band 4  Unknown
Sep 04 18:36:52 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:52 PM [CMD-NAME]        C1:E9:4D:54:A0:61 Mi Smart Band 4  Unknown
Sep 04 18:36:57 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:57 PM [CMD-MQTT]        monitor/pihole/C0:B8:98:9C:2C:A9 { ... confidence : 0 ... }
Sep 04 18:36:57 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:57 PM [CMD-MQTT]        monitor/pihole/C0:B8:98:9C:2C:A9 { ... confidence : 0 ... }
Sep 04 18:36:57 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:57 PM [CMD-NAME]        C0:B8:98:9C:2C:A9 Mi Band 3  Unknown
Sep 04 18:36:57 pihole-00 bash[23969]: [+] 0.2.197 04-09-2019 06:36:57 PM [CMD-NAME]        C0:B8:98:9C:2C:A9 Mi Band 3  Unknown**

I'm using the following "behavior" file:

# ---------------------------
#
# BEHAVIOR PREFERENCES
#
# ---------------------------

#MAX RETRY ATTEMPTS FOR ARRIVAL
PREF_ARRIVAL_SCAN_ATTEMPTS=1

#MAX RETRY ATTEMPTS FOR DEPART
PREF_DEPART_SCAN_ATTEMPTS=2

#SECONDS UNTIL A BEACON IS CONSIDERED EXPIRED
PREF_BEACON_EXPIRATION=240

#MINIMUM TIME BEWTEEN THE SAME TYPE OF SCAN (ARRIVE SCAN, DEPART SCAN)
PREF_MINIMUM_TIME_BETWEEN_SCANS=15

#ARRIVE TRIGGER FILTER(S)
PREF_PASS_FILTER_ADV_FLAGS_ARRIVE=".*"
PREF_PASS_FILTER_MANUFACTURER_ARRIVE=".*"

#ARRIVE TRIGGER NEGATIVE FILTER(S)
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE="NONE"
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="NONE"

PREF_ALIAS_MODE=false

Here's the issue: My gf and I have 2 Xiaomi Mi Band. Both of them are set to "Discoverable".

Monitor starts as a service using following command: ExecStart=/bin/bash /opt/monitor/monitor.sh -x -b -tad & This is the only monitor instance in the apartment.

From the log you can see that at first the confidence is 100, both the Mi Band are seen. After a second this confidence level goes to 0. This happens as soon as the band is no more seen as its complete name + alias ( C1:E9:4D:54:A0:61 juri_mi4 Anhui Huami Information Technology Co., Ltd. ) but as **Unknown**

Beside this initial scan, which I believe should not happen , because the flag is set to -tad which as I understood it means that the scan runs only when a message is published to its MQTT topic, when I try sending a MQTT message to this topic it seems that nothing happens.

I'm using MQTTBox client, I'm able to add a new entity to track simply by sending this message below which is part of what you wrote in the documentation: topic: monitor/setup/ADD STATIC DEVICE message: 00:11:22:33:44:55 alias

This is a simple test that tells me that I am able to send MQTT messages to this topic.

So, now the confidence is 0 for both of them and I'm home. I believe that sending a monitor/scan/depart will run the scan and see my devices, but this doesn't happen.

Moreover, I've been using this above command: ExecStart=/bin/bash /opt/monitor/monitor.sh -x -b -tad & For something like 3 months now. I have never, ever ran a scan by sending a MQTT message like above. It always runs scans by itself. It stays in background and constantly scans. This has the good effect that the sensor connected to Home Assistant gets updated constantly, the downside is I have no control over it. It happens very often that for some reason these Mi Band go in Standby. The scans start reporting 100, 0, 100, 0 ... and so on for, let's say, the whole night.

This is an example of what I mean: https://imgur.com/a/Rq9l7Sh

When it is 0 I'm most probably out of home, and in fact the line is completely flat. When I'm home, it starts going 100 and 0, neverending.

I tried to be as clear as possible but please forgive me if I'm not. Obviously, ask me anything. I will be more than happy to run all the test that you'd require.

Thanks for your hard work!

Leatherface75 commented 5 years ago

Same problem here with my phone so this is useless for room presence solution. Tried first with an older Bluetooth adapater and didn't work at all but i bought a new Bluetooth 4.2 adapter with BTLE and this works but this only works for home presence and not for room presence.

Nihvel commented 5 years ago

Well the problem is (luckily) limited to the Mi Band. I've been monitoring how my Huawei phone behaves and the sensor does not have false alarms. When I'm home the bluetooth scanning works, finds the phone and shows it to 100. When I'm not home, to 0. When it's 100, it stays to 100. There are no "double scans" where it is seen an unknown or such. It's I guess how it is supposed to be. But I don't walk around the rooms with the phone, it is the Mi Band that does because I wear it.

Leatherface75 commented 5 years ago

I have a Xiaomi phone and it has no problem to log RSSI with my Google Home mini speakers for example. Also have a Nexus 7 tablet and it's same problem there. Yes it shows 100 for me so it finds the phone but it doesn't know which room i am in because it shows 100 not 40-60 or similar like my Google Home mini speakers. With that it can know which room i am in but trying to get this to work to monitor a room without Google Home speaker.

Nihvel commented 4 years ago

This probably won't be addressed as it's not Monitor's fault rather the Xiaomi mi band. Smartphones like Huawei, Xiaomi, Samsung... Their bluetooth is stable and Monitor works great

Leatherface75 commented 4 years ago

No monitor is not working xith Xiaomi phone either for me.