MQTT, MQTTitude & OwnTracks

All,

I would like to use MQTT, MQTTitude and OwnTracks for localization of my iPhone and struggle a little with the syntax.

First I installed mosquitto on my Raspberry and after configuration it’s obviously running.
Then I installed MQTT and MQTTitude bindings in my openhab running on the same pi.
The openhab.cfg is configured accordingly (broker, lat/long, radius, user / passwd like in the mosquitto config).
OwnTracks is running on my iPhone in private mode and it seems to be connected (mosquitto.log):
1446029969: New client connected from 10.8.0.6 as mosquitto/NCO-i (c0, k60, u’mosquitto’).
1446029979: Client mosquitto/NCO-o disconnected.

But how do I configure the switch when I get home?
My item looks like this
Switch Ortung_Enzio “Enzio @ Home” { mqttitude=“Rasper_MQTT:<mqtt_topic>/NCO:home” } // MQTT topic = owntracks ??
Where Rasper is my and my iphone.
But what is <mqtt_topic>?

In the logs of mosquitto I can see a connection - actually two connections:
But why two???

1446060723: New client connected from 192.168.178.45 as mosquitto/NCO-o (c0, k60, u’mosquitto’).
1446060723: Client mosquitto/NCO-i disconnected.
1446060723: New client connected from 192.168.178.45 as mosquitto/NCO-i (c0, k60, u’mosquitto’).
1446060725: Client mosquitto/NCO-o disconnected.

See the Binding Config section of the MQTTitude Bind’s wiki page. It describes how to set a home geofence, region mode, manual mode, etc.

Thanks, but I have checked it out and I could not get the meaning of topic.
There is not topic which I could set in my OpenTracks iphone app.

By the way:
Why are just some variables shown in events.log
My switch Ortung_NCO (and others) are never mentioned in events.log.

It has been many months since I last played with OwnTracks but I do know there was a filed in the config on the iPhone app to put in a topic. Two topics actually, one where it publishes its updates and another where it can receive commands from openHAB.

The OwnTracks docs about topics are at this location.

Obviously both can connect to the mosquitto (mosquitto.log):

iPhone:
1446127823: New client connected from 192.168.178.45 as mosquitto/NCO-o (c0, k60, u’mosquitto’).

openhab:
1446127993: New client connected from 127.0.0.1 as openhab.1446127992926 (c1, k60, u’mosquitto’).

But I get an error in the mosquitto.log:
1446141763: Socket error on client openhab.1446127992926, disconnecting.
1446141801: New connection from 127.0.0.1 on port 1883.

In my openhab.log in Debug mode I can see:

19:57:10.152 [DEBUG] [.b.m.internal.MqttitudeBinding:177 ] - Registering Mqttitude consumer for owntracks/mosquitto/NCO-o (on Rasper_MQTT)
19:57:10.155 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:476 ] - Starting message consumer for broker ‘rasper_mqtt’ on topic ‘owntracks/mosquitto/NCO-o’
19:57:10.177 [DEBUG] [.b.m.internal.MqttitudeBinding:177 ] - Registering Mqttitude consumer for owntracks/mosquitto/NCO (on Rasper_MQTT)
19:57:10.179 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:476 ] - Starting message consumer for broker ‘rasper_mqtt’ on topic ‘owntracks/mosquitto/NCO’
19:57:10.183 [DEBUG] [.b.m.internal.MqttitudeBinding:84 ] - Activating Mqttitude binding
19:57:10.191 [DEBUG] [.b.m.internal.MqttitudeBinding:118 ] - Mqttitude binding configuration updated, ‘home’ location specified (Lat: xxx, Long: xxx) with a geofence of 100.0m.

So, obviously no error, but the switch is not updated.

Well, looking at the logs your topics are:

  • owntracks/mosquitto/NCO-o
  • owntracks/mosquitto/NCO

So your item needs to use the fully qualified topic name:

Switch Ortung_Enzio "Enzio @ Home" { mqttitude="Rasper_MQTT:owntracks/mosquitto/NCO:home" } // MQTT topic = owntracks

Yes, the log entry
owntracks/mosquitto/NCO
fits to my item
Switch Ortung_Enzio “Enzio @ Home” { mqttitude=“Rasper_MQTT:owntracks/mosquitto/NCO:home” }

But in the mosquitto log i just find
New client connected from 192.168.178.45 as mosquitto/NCO-o (c0, k60, u’mosquitto’).

So does this mean in the first case the topic is “owntracks/mosquitto/NCO” and in the second it’s:
mosquitto/NCO-o

No, the “New client connected” line is the name of the client, not the topic.

Alright, that makes sense.

Sorr, but I still do not understand, how to match both.
My assumption is that I define the variable (Switch “Ortung_Enzio”) and it will be looking in the mosquitto db for the location with the same name (topic).
So I though both “paths” must be the same like “mosquitto/NCO-o”.

Is that what you mean, that both must have the same topic?
But on my OwnTracks iOS App I do not have anything like “topic” - I guess that’s my original problem.
There are just:
TrackerID, DeviceID, (Host:port), TLS Authentication, UserID and password.

In the info “i” I see:
MQTT connection:
mqtt:/mosquitto@192.168.178.50:1883 c0 k60 as mosquitto/NCO-o
(I did not define the “-o” in my Device ID though)

You are combining a bunch of different concepts.

When you are working with MQTT, the following terms have a specific meaning:

  • Broker: the MQTT server
  • Client: a separate program that connects to MQTT. Each client provides a name when it connects. The name is completely independent from the Topic or Message
  • Topic: A named location where clients publish messages to or subscribe to messages from

For two clients to communicate they publish messages to a topic and subscribe for messages from the topic. More than one client can publish or subscribe to a single topic.

With that out of the way, the topic that is configured on your iOS app must be the same topic that the Switch is configured to use.

Per this web site for OwnTracks, which I already linked to above, the topic can be configured in the settings:

I think you have to go to the Settings app on iOS, not the OwnTracks app directly to get to the settings.

Thanks for your patience.
Actually broker, client and such is quite clear and I already found the OwnTracks website of course.
But the actual iOS App (8.3.2) looks totally different.
So my original problem is, that there is no information about the topic anymore:


It must have changed quite a bit since the last time I played with it. What
is in Publish Settings? That he at where I would expect to see the topic
settings.

According to Owntracks community discussions “Publish settings” is to write settings to a file modify it and put it back in.
Right now I am fine with the standard topic:
owntracks/mosquitto/NCOs_iPhone
owntracks/username/DeviceID

However, I do not see any location update in mosquitto just the entries of connection:
1446220566: New client connected from 10.8.0.6 as mosquitto/NCOs_iPhone (c0, k60, u’mosquitto’).
1446220573: Client mosquitto/NCOs_iPhone disconnected.

Although I have set several Regions in my Owntracks…
But, sorry this is off topic in this community.

I actually still struggle with this setup and did not find help anywhere else.
So maybe someone of you could comment on my issue (again ;-).

My item below works obviously (Switch will be updated when I am at home)
Switch Loc_Home “@ Home” { mqttitude=“mosquitto:owntracks/mosquitto/NCOs_iPhone” }
In this case “home” is configured in my openhab.cfg

I have generated regions in my Owntracks (e.g.) AHR and setup the related item:
Switch Loc_AHR “@ AHR” { mqttitude=“mosquitto:owntracks/mosquitto/NCOs_iPhone:AHR” }

When I change my location, I will get a push update from OwnTracks on my phone, but nothing happens on my openHAB.
The topic seems to be ok, as the “home” item works fine.
I currently run a VPN on my Raspberry to connect to openHAB.
It his maybe the issue, that the connection between my phone and mosquitto disconnects?

A general question:
I think it would be much easier, if you could handle centrally all regions within openhab.cfg (like the home zone).
This would make the setup of multiple mobile phones much easier.
Will this be possible in the future?

It seems ambiguous in the description on the wiki, but perhaps you can’t do Manual Mode and Region Mode at the same time. Remove the home settings from the openhab.cfg, restart openHAB, and see if it now works.

That’s possibly worth a try.
However, the topic might still be the central issue as I do not know if the following syntax is correct:
Switch Loc_AHR “@ AHR” { mqttitude=“mosquitto:owntracks/mosquitto/NCOs_iPhone:AHR” }
or if it must be something like
{ mqttitude=“mosquitto:owntracks/mosquitto/NCOs_iPhone/AHR/event” }

However, I found out that I can set different communication modes (quite, move, significant change, manual).

You are much better off using region mode. The mobile OSs are much better at delivering waypoint transition events to the Owntrack apps than relying on getting a location pub within your home location (in manual mode). The reason being if you have location updates set to say 500m and you get a location publish when you are 50m outside your home waypoint radius, then assuming your radius is only 100m you won’t see another location publish until you have moved 500m which won’t be till you head back out away from home.

Using region mode taps into the waypoint events generated by the underlying OS and provides a much more reliable method of detecting when you move in/out of these regions.

When trying to get this stuff working the first thing is to establish where your location publishes are going - i.e. what topic are they appearing on your broker. Once you know this you can start configuring openHAB as per the WIKI instructions.

Hi Ben,

thanks, for your hint.
I’ve set it up accordingly, but still struggle getting the information from mosquitto to openhab.
If I connect to mosquitto (mosquitto_sub) and listen to my phone’s messages at ‘owntracks/mosquitto/NCOs_iPhone’ (my base topic name), I can see the messages.

When pushing the publish button on the owntracks map view (arrow up):


I will get:
{“batt”:100,“lon”:xxxxx,“acc”:10,“p”:101.5356063842773,“vel”:0,“vac”:3,“lat”:xxxxx,“t”:“u”,“tst”:1446878149,“alt”:19,"_type":“location”,“tid”:“ES”}
This works with "publish waypoints etc as well.

However, when I set my openhab item to either old or new (according to the mqttitude binding help: https://github.com/openhab/openhab/wiki/Mqttitude-Binding)

Region Mode (old):    { mqttitude="<broker_id>:<mqtt_topic>:<region_description>" }
Region Mode (new):    { mqttitude="<broker_id>:<mqtt_topic>/event:<region_description>"

Which - in my case - results in

{ mqttitude="mosquitto:owntracks/mosquitto/NCOs_iPhone:Home" }

or

{ mqttitude="mosquitto:owntracks/mosquitto/NCOs_iPhone/event:Home" }

respectively.
I do not get anything into the items from mosquitto
“Home” of course is defined in my Owntracks App.

Any idea?
Your help is greatly appreciated.

Is your waypoint configured with share=true in the Owntracks app?

My only advice would be to manually subscribe to your broker to ensure you are definitely seeing the waypoint transition events on the expected topic and then double check that your openHAB item binding is using exactly the same topic.

If these all match, then I would be checking the Mqttitude binding logs to see if it is correctly connecting to your broker and is able to receive messages. It sounds like nothing is actually arriving at the binding so there may be something wrong with your connection settings (which are defined in openhab.cfg in the MQTT binding config).

Yes, all regions are shared in the iOS App.
According to my mosquitto logs my openhab connects without problems:

1446921581: New connection from 127.0.0.1 on port 1883.
1446921581: New client connected from 127.0.0.1 as openHAB (c1, k60, u'mosquitto').

But actually I do not see any log about information input of the APP.
However using mosquitto_sub shows all the data send to the topic mentioned above.

About your advice: Manually subscribe.
How to do that?