HASS.IO / MQTT / and IOS OwnTracks Setup Problems

Holy bananas I’m confused. :banana: First Reply is an update on progress

I want to be as thorough as I can in explaining this so I can attempt to write up a more comprehensive, simple step-by-step for the next guy…so, if you know how to do this and are willing to help, there’s a starbucks coffee in it for you :wink:

Tools:

MacBook OSX
HASS.IO - 0.56.2 on Pi3
MQTT add-on installed 1.0
iOS 11.0.2
OwnTracks 9.7.2

There are so many different conflicting pieces of information floating around and I’m simply trying to understand the basics of MQTT solely for the purpose of tracking my iPhone location with OwnTracks

In Hass.io, the following is set for Mosquitto options:

(never mind the indentations, I have it right in the setup):

{
“plain”: true, <— although I like bagels, I’m not certain
“ssl”: false, <— not sure what’s required to set SSL up
“anonymous”: false, <— I’m not completely useless…this makes sense
“logins”: [
{
“username”: “xxxxxxxx”, <— just made it up arbitrarily
“password”: “xxxxxxxx” <— same…
}
],
“customize”: {
“active”: true, < — I guess this enables the folder below?
“folder”: “mosquitto” <— not sure what this is for but I created the folder in samba share
},
“certfile”: “fullchain.pem”, <— wh…wha?
“keyfile”: “privkey.pem” <— ya…mind blown.
}

Network Host Ports are defaults at 1883 and 8883.

My router is port forwarding 1883 and 8883 to the Pi3 IP Address and DuckDNS is operating correctly (as far as I can tell…)

I don’t know what “Let’s Encrypt” is at this point, but Hass.io warns me not to enable it if I use DuckDNS. So, I abide.

Testing Mosquitto

When I restart the broker, I get this in the log:

starting version 3.2.2
1509137804: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1509137804: Config loaded from /etc/mosquitto.conf.
1509137804: Opening ipv4 listen socket on port 1883.
1509137804: Opening ipv6 listen socket on port 1883.
1509137804: Warning: Mosquitto should not be run as root/administrator.  

Seems to look good to me, except for that last line and the fact that I don’t really know what I’m doing. Not sure if that’s an error or general warning for the sake of warning.

OwnTracks on the iPhone

Not very well documented and a bit clunky…but I’ll do my best.

Settings Screen

  • Mode = Private
  • TrackerID = should something be here? It seems to have a little “04” below “Tracker.”
  • Export Settings – Haven’t touched it.
  • Publish Settings – Haven’t touched it.
  • DeviceID – Should I put something here or just go with the long nasty key that’s shown in the app by default?
  • Host – .duckdns.org
  • Port – 1883 (Do I turn Websockets ON or leave it OFF?)
  • Proto – This shows the number 4, which I believe is correct…but I don’t know about TLS.
  • Authentication – ON
  • UserID – the arbitrary user name I added in the Options for MQTT broker.
  • Password – same…
  • Secret encryption key <— Eh? Not sure

Status Info Screen

  • Location – Seems to be +/- 26m in accuracy. Hurray.
  • Connection – Parameters shown look something like this:

mqtt://[username]@http://[name].duckdns.org:1883 c0 k60 as [username]<device_id_string_from_settings_page>

  • Status – I see "idle the operation couldn’t be completed. (kCFErrordomainCFNetwork error 1.) { “_kCFStreamErrorCodeKey” = 1; “_kCFStreamErrorDomainKey” = 12; }

This error occurs both when I use both the public URL and the IP Address.

HASS.IO Config

mqtt:
…broker: core-mosquitto (minus the elipsis naturally)

Question

From what you see here, what am I missing?

Thank you!

Update

Local Connection Success

1. MQTT Changes made:

(Note: I made more than one change so I’m not sure which one or if both helped…)

  • Changed Options to “false” for “customize” : “active”

2. OwnTracks Changes made:

  • Arbitrarily named the Device ID to “45”

3. Configuration.yaml changes:

Changed this:

mqtt:
  broker: core-mosquitto

to...

mqtt:
  broker: <internal_ip>
  username: <username>
  password: <password>

I was able to connect to HASS.IO on the Pi3 with OwnTracks using the internal IP address of the Pi3.

Remote Connection Success Using IP Address

1. OwnTracks Changes Made:

  • Changes host IP address in parameter settings to <external_ip_address>

Still working on figuring out how to get it to work with DuckDNS.

I have successfully connected to HA using the HA iOS app and the DuckDNS address on port 8123, but something, perhaps the configuration options in the DuckDNS add-on has prevented me from connecting. Clearly port forwarding is working for both HA and Mosquitto because the external IP works for both.

1 Like

welcome to the struggle, im in the same phase as you are;-)) or ;-(( (you pick)

what happens when you stop the hassio mqtt add-on? from what i understand, one either uses that (preset to mqtt.org) , or uses the settings in the configuration file for the embedded broker (or any other you could specify).

i get the same own tracks error messages. must have to do with the ‘internal’ settings of the configuration file, and the external needs of own tracks

btw, from a security perspective i don’t like that the embedded broker uses the ApiPassword, and one has to enter that into the Owntracks app for connecting to it.

cheers,
lets keep this up till it works :slight_smile:
Cheerio
Marius

btw check Ben’s informative video: https://www.youtube.com/watch?v=VaWdvVVYU3A

no tls, no websockets he says. 4 is good.
hope this helps.
Marius

Thanks. That video doesn’t do it though because he’s using an Android device. I’ve managed to get Mosquitto operating properly (as far as my knowledge can take me) and I have both of my iOS devices running OwnTracks and both have been automatically detected and added to the known_devices.yaml.

The only challenge I’ve run into now is how to be able to use the DuckDNS URL in OwnTracks without getting an error.

Currently I’m using my ISP’s public IP to get into Mosquitto. If that changes, I’ll have to re-configure the phones again.

Is there a difference between the embedded broker and the MQTT add-on in Hass.io or are we talking about the same thing?

Cool! Please let us know how you configured both OwnTracks and the Hassio setup?
Through the config file, or the Hassio component?

Maybe both ?

As far as i understand it now, the Hassio component is the MQTT.org broker, and is different from the embedded one. Not sure though, figuring it out myself tbh…

Cheers
Marius

well some progress made.
Ive been able to establish a connection in Owntracks…
had to port forward the 1883 and 8883 to the hassio ip.

it only connects to 1883 though. Selecting ssl: true or false in the Mqtt add-on doesn’t make a difference in that.

still, im only connected when my phone is on the wifi, and vpn is switched off. Thats a most insecure combination. Alright for home testing purposes, but never allowed outside .

btw: i’ve got nothing declared in the configuration.yaml. Not even the plain mqtt: . Let alone the login credentials or other configuration details. Thought i’d let take the add-on take care of the details.

@arretx any succes connecting when on 4g, or vpn ?

Piggybacking on this (I’m also struggling):

I wonder what’s up with:

I would expect that to mean the parameters are discovered automatically when using Hassio and the Mosquitto add-on but that doesn’t seem to be the case. I did see a message in the log:

2017-11-05 21:17:38 ERROR (Thread-2) [homeassistant.components.mqtt] Unable to connect to the MQTT broker: Connection Refused: not authorised.

so I guess address and port are auto discovered and authentication data isn’t.

I tried searching the source code for core-mosquito and couldn’t find it. Shrug.

according to my mqtt log, there’s a successful connection being made, several as a matter of fact.

Without going into all specific programming of events just yet, for starters i would like to have a window displayed of all streams being polled.
How would i have to realize that?

i have 2 options i think:

  • display everything that is sent to the mqtt broker
  • poll a local mqtt sender on my network. I think i should be able to do that by entering the Macaddress/# , or name/# which i did in the config file through this code

mqtt_eventstream:
subscribe_topic: mosqpub/#
but how to display that in the front-end .

Please help…
Cheers,
Marius

Are you on a Windows or OSX environment? I use a program call MQTT.fx to see what’s happening on my broker.

hi,
sorry missed your reply.

my HA is an Hassio install, and i use an OSX machine.

got the mqtt working at the moment, subscribed to several sensors, and command_line several switches.

Cool…no worries.