MashupMill / docker-presence-monitor

Docker container image for the bluetooth presence monitor found at https://github.com/andrewjfreyer/monitor
MIT License
15 stars 5 forks source link

Docker-compose #1

Open vamichael opened 5 years ago

vamichael commented 5 years ago

Could you add an example docker-compose.yml?

vamichael commented 5 years ago

I came up with this

  monitor:
    image: mashupmill/presence-monitor:0.2.197
    container_name: monitorNUC
    depends_on:
      - mqtt
    restart: unless-stopped
    network_mode: host
    privileged: true
    environment:
      - MQTT_ADDRESS=127.0.0.1
      - MQTT_USER=mqtt
      - MQTT_PASSWORD=mqttpass
      - MQTT_TOPICPATH=monitor
      - MQTT_PUBLISHER_IDENTITY=mydocker
      - MQTT_PORT=1883
      - MQTT_VERSION=eclipse-mosquitto
      - KNOWN_STATIC_ADDRESSES=88:FF:FF:79:63:A0 MyIpad
      - MQTT_CERTIFICATE_PATH=''
    volumes:
      - ${USERDIR}/stacks/homeautomation/monitor/config:/config

However, I don’t know what to use for MQTT_CERTIFICATE_PATH. I have that as blank in the non docker version and it works. I haven’t a clue as what to use here. This is from the container log

 * Starting D-BUS system messagebus ... [ ok ],
 * Setting hostname ... [ ok ],
 * Starting Bluetooth ... [ ok ],
> updated monitor (v. Unknown) -> (v. 0.2.197)...,
using /config as config dir,
> error: please check mqtt certificate path in mqtt_preferences,
 * Stopping Bluetooth ... [ ok ],
 * Stopping D-BUS system messagebus ... [ ok ],
,
ammmze commented 5 years ago

If you don't have SSL encryption on your MQTT instance, then you can just omit that environment variable :)

Here's relevant part of my docker-compose ...

version: '2.4'
services:
  monitor:
    container_name: monitor
    image: mashupmill/presence-monitor:latest-armv6
    network_mode: host
    privileged: true
    restart: unless-stopped
    command: ['-b']
    volumes:
      - /etc/localtime:/etc/localtime:ro
    environment:
      MQTT_ADDRESS: 192.168.0.10
      MQTT_USER: mqtt
      MQTT_PASSWORD: "***********"
      KNOWN_BEACON_ADDRESSES: |
        FF:FF:FF:FF:FF:FF Red Tag
        FF:FF:FF:FF:FF:FF Green Tag
        FF:FF:FF:FF:FF:FF White Tag
        FF:FF:FF:FF:FF:FF Black Tag
      KNOWN_STATIC_ADDRESSES: |
        FF:FF:FF:FF:FF:FF Alpha Phone BT
        FF:FF:FF:FF:FF:FF Beta Phone BT

Though I will warn that I haven't found it to be very stable yet. After a few days the process seems to hang. When I jump into the container, I find that there are some zombie processes that don't seem to get cleaned up. And my attempt at adding a health check (in addition to adding an 'autoheal' container) to re-create the container didn't work. Right now my attempt at a health check is to basically listen to the main_pipe which is where all the various things that are running writes messages to which are then picked up by the main process. I then write out a timestamp each time a message is received in the main_pipe and the health check basically just checks that we've received a message within the last N seconds. So it seems that even when the process hangs, there are still some things still writing to the main_pipe.

The other idea I had for a health check is to listen for the online status message that gets pumped out every so often and basically do the same thing...so if we haven't received an online message in the last N seconds from when the health check runs, then we would consider it unhealthy.

But all-in-all the health check is just a bandaid until I can figure out why the process ends up hanging after a few days.

vamichael commented 5 years ago

I'm having bigger fish to fry, namely just getting this working on a "normal" installation. Do you know if the MAC address ID of your devices should show up in the -b scan? I have a bunch of Apple devices, and I see "Apple" in the log, but nothing matching my MAC addresses in my devices. Very strange. I'll probably come revisit the image again after things settle down. Considering these I'm not going to run any services on a Zero besides these, the juice may not be worth the squeeze

ammmze commented 5 years ago

I wanna say I recall reading in one of the posts about monitor.sh that the broadcasted id are random or something. I don't have an apple phone, so I'm not really sure though. Our android devices don't appear to broadcast anything, so the best we can do for now I think is add the id of our phones in as a KNOWN_STATIC_ADDRESSES which monitor.sh will periodically make a request to for the device name. We then picked up a 4 pack of cheap bluetooth LE tags on amazon which we put in our cars which do broadcast their address and those get picked up when our vehicles come home.

But actually for now, i've resorted back to using my wifi detection because I haven't gotten this stable enough. I kept finding the process had hung and the confidence level in home assistant would get left at 100 even though I was gone...so the house was left un-secured :\ But I think I may be able to at least fix that by setting an expire_after in my sensor, but haven't had time to mess with it.