MQTT, MQTTitude & OwnTracks

[quote=“sptzdmnc, post:39, topic:3744, full:true”]
Btw: If i start my phone, or if i got a weak internet connection (Even if i connect again) the MQTT is and stays marked as disconnected. [/quote]

Are you using a CA certificate and TLS authentication?
I had a similar problem while doing this because I had imported the ca key from my network storage device. I looks like owntracks checks the certificate more often and it has to be on your phone on internal or external sd card.
After copying the certificate to my phone locally everything went fine.

[quote=“sptzdmnc, post:39, topic:3744, full:true”]
If the device is in standby mode, i won’t get any status update.[/quote]

GSM should be always on, but you are able to influence wifi behaviour: do a search for your specific android version and look for “wifi always on in standby”. Normally you would find that setting in the advanced menu for wifi. Set it to “Wifi always on during standby” or something similar. It also saves you some battery.

Good luck.

I’ve got a really stupid question, but I just cannot figure out this myself.
I’m getting owntracks mqtt messages and decode them in the rule:

rule "MQTT Owntracks SJ"
  when 
    Item mqttPositionSJRaw changed
  then
  	logInfo("MQTT", "MQTT Owntracks SJ data received")
    val String json = (mqttPositionSJRaw.state as StringType).toString
    val String type = transform("JSONPATH", "$._type", json)
    if (type == "location") {
      val String lat  = transform("JSONPATH", "$.lat", json)
      val String lon  = transform("JSONPATH", "$.lon", json)
      val String acc  = transform("JSONPATH", "$.acc", json)
      val String batt = transform("JSONPATH", "$.batt", json)

      mqttSJLatitude.postUpdate(lat)
      mqttSJLongitude.postUpdate(lon)
      locationSJ.postUpdate(new PointType(lat + "," + lon))
      mqttSJAccuracy.postUpdate(new DecimalType(acc))
      mqttSJ_XperiaBattery.postUpdate(new PercentType(batt))
    }
end

How can I display a map in OH with a simple dot where the coordinates are.

Thanks!!!

Create a Location item and put it in a group:

Group Locations
Location locationSJ (Locations)

Add the group to the sitemap:

Group item=Locations

Have your rule update the location item when the MQTT data comes in as you’re currently doing.

@watou Thanks for reply. It’s not working… Displaying an empty page.
I see the data is coming an rule is working.
Events:

2016-04-01 20:54:08 - mqttPositionSJRaw state updated to {"_type":"location","acc":12,"batt":57,"lat":-XX.8598381,"lon":XX.6356844,"tid":"sj","tst":1459497248} 2016-04-01 20:54:08 - mqttSJLatitude state updated to XX.8598381 2016-04-01 20:54:08 - mqttSJLongitude state updated to XX.6356844 2016-04-01 20:54:08 - locationSJ state updated to XX.8598381,XX.6356844 2016-04-01 20:54:08 - mqttSJAccuracy state updated to 12 2016-04-01 20:54:08 - mqttSJ_XperiaBattery state updated to 57

Can I isplay it without creating map.html?
Cheers!

Hi Sasha, it works for me to have a Location item in a Group widget, and then in the Classic UI, navigate into the group. The Android client does not work because I think it does not have map support (would be nice). I haven’t used the iOS app.

Oh, that’s strange… Thanks anyway!

No, mqtt runs without a certificate, but its encrypted.
I will implement a certificate when i create my new “smarthome VM” which includes my services.
At the moment mqtt is hosted within a docker container.

Hi sasha_jpr,

Can you please post your items config for this as i am trying to replicate it!..

Cheers!

Hi sasha_jpr,

Can you please post your items config for this as i am trying to replicate it!..

Cheers!

@sasha_jpr

Hi sasha_jpr,

Can you please post your items config for this rule as i am trying to replicate it!.. I cannot figure out where to post the data when it comes in and if i set it as a switch i get “Error during the execution of rule ‘MQTT Owntracks JC’: Cannot cast org.openhab.core.types.UnDefType to org.openhab.core.library.types.StringType”

Cheers!

Sorry mate, I haven’t used it for a very long time and looks like I haven’t saved it, sorry.

No problem. I got it all working. Thanks!!

Cheers,
Jay.

Hi Guys,

Anyone know how i can pull the value of rad out of this string in a rule to update an item. This is a little different then normal as its a string within a string…

{"_type":"waypoints","waypoints":[{"_type":"waypoint","tst":1486582266,"lat":42.771794842596,"lon":-78.834592094718,"rad":0,"desc":"Home"}]}

You will want to look at a json transformation. Not too tricky. There are a few examples on the forums.

Thanks. This is way old lol

Cheers,
Jay.

Sheesh. 9 days is like a flash in the pan with my hectic life!

Hahahah. Gotta keep up man! Lol

Cheers,
Jay.

Check yer Facebook messages. I think i messaged u.

Cheers,
Jay.

Like this?
You just need to look for type=waypoints instead of location mentioned below.

rule "Mqtt Postion XXX"
when 
	Item mqttPositionXXXRaw received update
then
    val String json = (mqttPositionXXXRaw.state as StringType).toString
    val String type = transform("JSONPATH", "$._type", json)
    if (type == "location") {
		val String lat  = transform("JSONPATH", "$.lat", json)
		val String lon  = transform("JSONPATH", "$.lon", json)
		val String acc  = transform("JSONPATH", "$.acc", json)
		val String batt = transform("JSONPATH", "$.batt", json)
		val String tst = transform("JSONPATH", "$.tst", json)
		
		mqttXXXLatitude.postUpdate(lat)
		mqttXXXLongitude.postUpdate(lon)
		Location_XXX.postUpdate(new PointType(lat + "," + lon))
		mqttXXXAccuracy.postUpdate(acc)
		mqttXXXBattery.postUpdate(batt)
		var DateTime time_tmp_D = new DateTime(Long::parseLong(tst) * 1000L)
    	mqttXXXTimeSt.postUpdate(new DateTimeType(time_tmp_D.toString))
    }
    logInfo("geofencing.rules", "Position update - XXX (" + mqttPositionXXXRaw.state + ")")
end

Hi, i wanted to install mqtt and owntracks, but it doesn´t work.

I´m on latest OH2 Snapshot version. I use a android Phone with Owntracks installed and a debian server with OH2 and mosquitto running on it.

I configured the mqtt.cfg inside openhab.

But i can´t connect with owntracks to mosquitto.

Can anybody help me?

Settings in owntracks on phone:
host: 192.168.102.23 (ip from debian-server)
Port: 1883

Username/pswd are set inside mosquitto and are entered in owntracks.

I don´t get a connection inside my local network. With dyndns and portforwarding of 1883/8883 tcp to debian server the same problem when outside and made changes to owntracks.

Is there a way to check, where i made some wrong settings? First i want to get the connection owntracks-mqtt running, after that i will start with OH2 settings.