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

To answer my question. I may have found a fix and setup rssi to track when phone is in what room. This user had poked into the monitor’s code and found a fix to the incorrectly report of -99 by commenting out a line.

Tested for a day now and seems to be working quite good.


I’ve been using this for years but recently had to update the Pi monitor was running on and now monitor regularly throws “write error: Broken pipe” at various places within support/btle script.

Has anyone else have the same issue, anyone found a fix?

Hi guys
Could someone please help

I’ve been using monitor for a while and everything has been fine, yet recently when I fire a arrive command it doesn’t see my known devices, same happens when I log into the pi.

Yet when I reboot the pi it finds them!

What could be the cause?

I was using this for a while, I always had trouble with maintaining a connection. I’ve since built it in node red. It constantly pings the nodes and reboots them daily. Also if they become unresponsive.

It constantly pings the nodes and reboots them daily.

Can you share your setup/ codes on implementing it to monitor? Though I do not use node red. Straight yaml.

If you publish .../echo to the topic the monitor nodes are on, it will respond back ok. Every minute I publish and then listen for the response, if it fails for 5 min it sends a reboot command.

Monitor usually locks up and the pi is still accessible. I reboot with a shell command over ssh

restart104: ssh -i /config/ssh/id_rsa2 -o 'StrictHostKeyChecking=no' [email protected] sudo shutdown -r


I restart the monitor PI every night at 04:01h, since then no problems. :rofl: :rofl: :rofl:

Hello. Can someone tell me what setting is best to have the node detect devices quickly after the arrive scan is initiated? When I first set it up, it was quite fast, now it is slow.

I have 4 nodes in total and I used the OP suggested settings that is provided in the github page. The main node is at the main entrance just a few feet once I enter the door, but it isn’t picking up fast enough for my announcement automation.

1 x node is set to: -tr -b
3 x nodes are set to: -tdr

Hi Tinkerer,
I know this is a really old post and I’m a complete noob when it comes to linux
I’m having a issue where monitor will stop reporting the correct confidence (showing zero even when it shouldn’t) and it won’t report correctly until I reboot the device.

I’ve read how to create a cron job I believe the following should be correct to run every minute

* * * * * /home/pi/monitor-watcher.sh
* * * * * /home/pi/system-watcher.sh

do I need to make any changes to your sh files to make this work for my PI zero or can I copy yours?

You should be able to use them as I wrote them, or make changes if you find need to trigger a reboot on a different string.

1 Like

Sorry what do you mean on a different string?

dmesg|tail -n 20|grep -q "Fixing recursive fault but reboot is needed!"
if [ ${?} -eq 0 ]; then
	/sbin/reboot --no-wall

There I wrote it to reboot if the dmesg contains Fixing recursive fault but reboot is needed in the last 20 lines.

Adjust to suit the message you’re seeing, if it differs.

Really sorry to be rude.
What is this for, why would this happen
As I mentioned I don’t really know linux

Monitor seems to stop seeing my devices. running your two scripts will that help with my problem?

Why would what happen?

Depends on what the cause of your problem is. I wrote those two scripts to:

  1. Restart monitor if it had appeared to hang (no output in over 300 seconds)
  2. Reboot the host if dmesg has the message Fixing recursive fault but reboot is needed!

You need to check the output from monitor to see if you’re seeing it hang, or if there’s something else going on

journalctl -u monitor -n 50

Then you need to check the output of dmesg to see if that error appears

dmesg|grep "Fixing recursive fault but reboot is needed!"

for some reason monitor stops accepting MQTT commands every now and then. I’ve tried to use your scripts but with my limited knowledge of linux I’m not able to determine why, it’s causing this issue

so after a lot of googling I’ve created an automation that pings echo to monitor every 5mins and if it doesn’t receive a response, then issue a command to reboot the pi. not elegant i know :grimacing:

Hi guys

I’ve a spare rpi4 and I thought I’d fire up monitor on it seeing as the pi4 has a better Bluetooth chip than the pi zero.

I’m finding that the pi zero is faster. Has anyone else tried a pi4 and how are you finding it?

after some updates of the rpi zero w, I am seeing this error from the logs. Anyone knows how to fix this? Have tried several reboots. Works for a few hours than same errors appears. It is happening to all 4 of the pi zero w.

Can’t create connection: Input/output error


ws1@ws1:~ $ sudo systemctl status monitor
[sudo] password for ws1:
● monitor.service - Monitor Service
 Loaded: loaded (/etc/systemd/system/monitor.service; enabled; vendor preset: enabled)
 Active: active (running) since Sun 2023-01-08 04:01:00 JST; 3h 52min ago
 Main PID: 11269 (bash)
 Tasks: 7 (limit: 2178)
 CGroup: /system.slice/monitor.service
 ├─11269 /bin/bash /home/ws1/bin/mqtt/monitor/monitor.sh -tad &
 ├─11395 /bin/bash /home/ws1/bin/mqtt/monitor/monitor.sh -tad &
 ├─11399 /bin/bash /home/ws1/bin/mqtt/monitor/monitor.sh -tad &
 ├─11402 /bin/bash /home/ws1/bin/mqtt/monitor/monitor.sh -tad &
 ├─11405 /bin/bash /home/ws1/bin/mqtt/monitor/monitor.sh -tad &
 ├─11407 /usr/bin/mosquitto_sub -I genkan --cafile /mnt/www/.ssl/mqtt-ca.crt -v -F %t|%p -q 2 -L mqtt://mqttuser mqttuser homeassistant.local 8883 monitor/# --will-topic monitor/genkan/status --will-payload offline
 └─28746 sleep 10

Jan 08 04:03:00 ws1 bash[11269]: [+] 0.2.200 08-01-2023 04:03:00 AM [CMD-NAME] FC:18:3C:0E:16:C0 tomokun Apple Inc
Jan 08 04:03:10 ws1 bash[11269]: [+] 0.2.200 08-01-2023 04:03:10 AM [CMD-MQTT] monitor/genkan/isp { ... confidence : 0 ... }
Jan 08 04:03:13 ws1 bash[11269]: [+] 0.2.200 08-01-2023 04:03:13 AM [CMD-NAME] 54:9F:13:8A:CE:48 ISp Apple Inc
Jan 08 04:03:15 ws1 bash[11269]: [+] 0.2.200 08-01-2023 04:03:15 AM [CMD-MQTT] monitor/genkan/id { ... confidence : 100 ... }
Jan 08 06:54:44 ws1 bash[11269]: Can't create connection: Input/output error
Jan 08 06:56:41 ws1 bash[11269]: Can't create connection: Input/output error
Jan 08 06:57:53 ws1 bash[11269]: [+] 0.2.200 08-01-2023 06:57:53 AM [CMD-MQTT] monitor/genkan/id { ... confidence : 90 ... }
Jan 08 06:58:12 ws1 bash[11269]: [+] 0.2.200 08-01-2023 06:58:12 AM [CMD-MQTT] monitor/genkan/id { ... confidence : 45 ... }
Jan 08 06:58:21 ws1 bash[11269]: [+] 0.2.200 08-01-2023 06:58:21 AM [CMD-MQTT] monitor/genkan/id { ... confidence : 0 ... }
Jan 08 06:58:25 ws1 bash[11269]: [+] 0.2.200 08-01-2023 06:58:25 AM [CMD-NAME] 1C:36:BB:A2:A0:BC iD Apple Inc

I’m migrating my HA to docker, anyone made docker image and docker-compose config they can share?

Sorry deleted my own post…

EDIT: Sharing…
Created Ubuntu Core image in Docker hub with the following:
Core, Nano, Git, Bluez, Bluez-hcidump, moquitto, mosquitto-clients, iputils-ping

Docker compose

    container_name: ubuntu
    image: "vtanid/image:ubuntu-core-lts"
    hostname: ubuntu
    restart: always
      - /opt/ubuntu/home:/home
      - /opt/ubuntu/data:/data
      - /run/dbus:/run/dbus:ro
    privileged: true
    network_mode: host
     - NET_ADMIN
    stdin_open: true 
    tty: true

Since there is no systemctl in the container.

I’m getting the following when publishing monitor/scan/restart

monitor.sh: line 1207: systemctl: command not found

What todo, what to do??? Any ideas??

I feel like I’m going mad! :smiley:
Could have sworn when I first started using Monitor it wasn’t possible to add iPhones as they randomised bluetooth MAC addresses? But I’ve been hearing/seeing that it IS possible? Furthermore I just added my iphone’s MAC to known_static_addresses and it showed up just fine?
What gives?! Did I just misunderstand years ago?