Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential port conflict when running MQTT and Monitor on same RPi? #15

Open
sbowater opened this issue Feb 8, 2020 · 5 comments
Open
Labels
bug Something isn't working

Comments

@sbowater
Copy link

sbowater commented Feb 8, 2020

Version of the add-on
1.0.0

Describe the bug (config/log below)
I am running the HassIO MQTT broker add-on in addition to this Presence Monitor add-on under HassOS on my primary RPi. As an aside, I have three other nodes that only run the Monitor script (RPi Zero W).

I have noticed that the instance of the Monitor script run via this add-on does run it's own internally-triggered scans and provide those MQTT reports (as expected) but most of the time will not respond to requests sent via MQTT (e.g., monitor/scan/echo, monitor/scan/known device states, monitor/scan/arrive, monitor/scan/depart). The instances running on separate RPi's always respond to these MQTT requests as expected.

It got me wondering if there is a fundamental design issue when trying to run the MQTT broker and the Monitor process on the same node. I do not claim to understand linux architecture and especially not Docker, but I thought only one process can listen to a TCP port. If so, I could see the MQTT broker binding to port 1883 and not allowing the monitor script to also listen in on this port (either very often or at all). Is that a potential issue with this approach?

If not, could it be that the HassIO RPi is just too busy to allow a response? It's not as if the incoming MQTT requests are queued up and a response is eventually received, they are just ignored.

Configuration


mqtt:
  broker: 192.168.2.161
  port: 1883
  username: '!secret mqtt_broker_username'
  password: '!secret mqtt_broker_password'
  topic_root: monitor
  publisher: noc
  certfile: ''
  version: ''
known:
  beacons: []
  static:
    - '!secret steves_phone'
    - '!secret mollys_phone'
blacklist: []
log_level: info
extra_arguments: '-a -x'

Log:


-----------------------------------------------------------
 Add-on version: 1.0.0
 You are running the latest version of this add-on.
 System: HassOS 3.9  (armv7 / raspberrypi4)
 Home Assistant version: 0.105.2
 Supervisor version: 199
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to DEBUG
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] monitor.sh: executing... 
[09:15:59] INFO: Updating running configuration...
# ---------------------------
# 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="0x1a|0x1b"
PREF_PASS_FILTER_MANUFACTURER_ARRIVE="Apple"
# ARRIVE TRIGGER NEGATIVE FILTER(S)
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE="NONE"
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="NONE"
# REPORT A 'home' OR 'not_home' MESSAGE TO .../device_tracker
PREF_DEVICE_TRACKER_REPORT=false
# ---------------------------
# MQTT PREFERENCES
# ---------------------------
# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address='192.168.2.161'
# MQTT BROKER PORT
mqtt_port='1883'
# MQTT BROKER USERNAME
mqtt_user=REDACTED
# MQTT BROKER PASSWORD
mqtt_password=REDACTED
# MQTT PUBLISH TOPIC ROOT
mqtt_topicpath='monitor'
# PUBLISHER IDENTITY
mqtt_publisher_identity='noc'
# MQTT CERTIFICATE FILE
mqtt_certificate_path=''
# MQTT VERSION (EXAMPLE: 'mqttv311')
mqtt_version=''
# ---------------------------
# LIST OF MAC ADDRESSES TO IGNORE, ONE PER LINE
# ---------------------------
# ---------------------------
# STATIC MAC ADDRESS LIST
#   Format: 00:00:00:00:00:00 Alias #comment
# ---------------------------
re:da:ct:ed:xx:xx steve
re:da:ct:ed:xxx:xx molly
# ---------------------------
# BEACON MAC ADDRESS LIST; REQUIRES NAME
#   Format: 00:00:00:00:00:00 Nickname #comments
# ---------------------------
[cont-init.d] monitor.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[09:08:06] INFO: Starting required services...
Starting system message bus: dbus.
Starting bluetooth: bluetoothd.
[09:08:06] INFO: Updating Bluetooth Presence Monitor to latest version...
HEAD is now at 87d433b Merge pull request #289 from hmmbob/patch-1
Already up to date.
[09:08:07] INFO: Starting Bluetooth Presence Monitor...
> updated monitor (v. Unknown) -> (v. 0.2.200)...
> using custom config directory [/opt/monitor]
> warning: verbose logging is enabled. this setting is only for informational and debugging purposes
> report all scan results mode enabled
> retaining mqtt status reports
using /opt/monitor as config dir
> preference: minimum time between the same type of scan = 15
> preference: regex filter for flags to accept = 0x1a|0x1b
> preference: regex filter for flags to reject = NONE
> preference: regex filter for manufacturers to accept = Apple
> 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
> re:da:ct:ed:xx:xx confidence topic: monitor/noc/steve (has not previously connected to hci0)
> re:da:ct:ed:xx:xx confidence topic: monitor/noc/molly (has not previously connected to hci0)
> log listener pid = 512
> btle scan pid = 513
> btle text pid = 514
> btle listener pid = 516
> mqtt listener pid = 517
> packet listener pid = 519
> beacon database time trigger pid = 521
[-] 0.2.200 08-02-2020 09:08:11 AM [CMD-INFO]	**** started arrival scan [x1 max rep] **** 
[-] 0.2.200 08-02-2020 09:08:11 AM [CMD-SCAN]	(No. 1) re:da:ct:ed:xx:xx arrival? 
[-] 0.2.200 08-02-2020 09:08:16 AM [CMD-MQTT]	monitor/noc/steve
 {
    "id":"re:da:ct:ed:xx:xx",
    "confidence":"0",
    "name":"steve",
    "manufacturer":"Apple Inc",
    "type":"KNOWN_MAC",
    "retained":"true",
    "timestamp":"Sat Feb 08 2020 09:08:16 GMT-0600 (CST)",
    "version":"0.2.200"
 }
[-] 0.2.200 08-02-2020 09:08:16 AM [CMD-MQTT]	monitor/noc/steve/rssi
[-] 0.2.200 08-02-2020 09:08:19 AM [CMD-SCAN]	(No. 1) re:da:ct:ed:xx:xx arrival? 
[-] 0.2.200 08-02-2020 09:08:23 AM [CMD-MQTT]	monitor/noc/molly
 {
    "id":"re:da:ct:ed:xx:xx",
    "confidence":"100",
    "name":"molly",
    "manufacturer":"Apple Inc",
    "type":"KNOWN_MAC",
    "retained":"true",
    "timestamp":"Sat Feb 08 2020 09:08:22 GMT-0600 (CST)",
    "version":"0.2.200"
 }
[-] 0.2.200 08-02-2020 09:08:26 AM [CMD-INFO]	**** completed arrival scan **** 
@sbowater sbowater added the bug Something isn't working label Feb 8, 2020
@pointlevel
Copy link

Experiencing the same thing, that it rarely responds to messages. Sometimes they come through and the answer is delivered, but rarely. Runnning same setup as @sbowater and the Pi zeros working fine.

@pedromargarido
Copy link

Same problem here!

@Limych
Copy link
Owner

Limych commented Apr 16, 2020

Very strange. Addon does not open any ports. MQTT is used only in client mode. The MQTT server is not even installed. The conflict simply has nowhere to come from ...

I will study the problem later - now, sorry, because of quarantine, I have to spend a lot of extra time on my main job.

@hdprice
Copy link

hdprice commented Jul 16, 2021

I'm running monitor on a separate Pi and it's not responding to published messages from Home Assistant. Would love to resolve this.

@averater
Copy link

averater commented Dec 7, 2023

I also have this issue. scan results are published fine on mqtt but it does not recieve any messages. It has been soon 4 years!

Is it an issue with docker? Do I have to run monitor standalone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants