Display google map of Owntracks MQTT GPS data - JS transform issues

1,370 views
Skip to first unread message

Scott K

unread,
Jun 3, 2014, 10:50:18 PM6/3/14
to ope...@googlegroups.com
I'm trying to do what Dan shows in the tricks section:  display a google map showing the GPS location posted by OwnTracks / MQTTitude.  Anthony recently did it and was successful, but I'm having trouble.

https://github.com/openhab/openhab/wiki/Samples-Tricks#how-to-display-google-maps-in-a-sitemap-from-a-mqttitude-mqtt-message

I can only get it to displays a blank google map - instead of the map, I just get the gray area where the map should be, but I do see the Google Map zoom bar and the yellow guy and the navigation compass.  I've narrowed the problem down to this:

String Location_Dan_Phone {mqtt="<[home:owntracks/daniel/iphone5s:state:JS(mqttitude-coordinates.js)]"}

For troubleshooting, I put the string item "Location_Dan_Phone" on the sitemap, and it displays a "-".  If I make another String Item that is just the GPS MQTT data without the JS transform, I'm able to display it in the sitemap, and it's the same text as I see from mosquitto_subing the topic shows up.  So the MQTT message of the GPS is coming in OK, but something is wrong with my transform.

I wasn't certain if I created <mqttitude-coordinates.js> the way OpenHAB likes them.  I used "nano mqttitude-coordinates.js" in </openhab/configurations/transform>, and copy and pasted what's in Dan's tutorial:

var location = eval('(' + input + ')');
result = location.lat + "," + location.lon;

In Dan's JS transform file, the <mqttitude-coordinates.js>, how does OpenHAB interpret the .lat and .lon?  <location> was just declared a "var"...how does OH know that a var has a .lat and .lon, or even how many bytes lat and lon are?  Is this structure predefined somewhere?

Maybe I'm missing this definition, maybe I was suppose to have put an addon in the addon folder that defines .lat and .lon?


dan cunningham

unread,
Jun 4, 2014, 8:03:06 AM6/4/14
to ope...@googlegroups.com
Jan-Piet Mens gave a good explanation in the other mqtt thread of how the javascript is being parsed, that part should work.

It sound like mqtt is not setup correctly.  Can you post your mqtt config (sanitized of passwords and such)?  


--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

Scott K

unread,
Jun 4, 2014, 12:05:58 PM6/4/14
to ope...@googlegroups.com
Oh, ok.  I didn't see JP's post because I felt bad about pirating Anthony's thread with my own problems, so I started my own.

Thanks to you both.  I'll post my MQTT config when I get back home.

I think MQTT is passing the data correctly to OpenHab.  I know a lot of the no data "-" issues can be cause by MQTT-OpenHAB connections, but in my case, I made another String item that is the original MQTT message without the JS transform, and I put that on the sitemap, and I can see that string update on the OpenHAB UI when I force Owntracks to report its coordinate.

When JP saids "the payload passed to the transformation is JSON" - does that require any special configuration on the part of MQTT config?

I'd like to troubleshoot whether the transform is actually running or not.  Maybe instead of 

result = location.lat + "," + location.lon;

 I can check that the transform is running by doing <result = "Hello world">?

I'll report back.

dan cunningham

unread,
Jun 4, 2014, 12:17:45 PM6/4/14
to ope...@googlegroups.com

If it helps, here's what a successful series of events (sanitized a little)  looks like in the log , I have the the mqtt bindings using trace logging in logback_debug.xml

10:11:29.111 TRACE o.o.i.t.m.i.MqttBrokerConnection[:562]- Received message on topic 'owntracks/daniel/iphone5s' : {"t":"u","tst":"1401898290","acc":"65","_type":"location","lon":"-100.000","lat":"100.000","batt":"70"}
10:11:29.111 DEBUG o.o.c.t.i.s.JavaScriptTransformationService[:61]- about to transform '{"t":"u","tst":"1401898290","acc":"65","_type":"location","lon":"-100.000","lat":"100.000","batt":"70"}' by the Java Script 'mqttitude-coordinates.js'
10:11:29.185 DEBUG o.o.c.t.i.s.JavaScriptTransformationService[:61]- about to transform '{"t":"u","tst":"1401898290","acc":"65","_type":"location","lon":"100.000","lat":"100.000","batt":"70"}' by the Java Script 'mqttitude-maps.js'


 logback_debug.xml should have these lines

        <logger name="org.openhab.binding.mqtt" level="TRACE" />
        <logger name="org.openhab.io.transport.mqtt" level="TRACE" />
        <logger name="org.openhab.binding.mqttitude" level="TRACE" /


--

Scott K

unread,
Jun 4, 2014, 9:42:54 PM6/4/14
to ope...@googlegroups.com
Here's what my OpenHAB looks like:

http://www.tiikoni.com/tis/view/?id=5b24c77

You can see the "prior to transform" string coming in from MQTT - this is the raw string, not transformed.  The image you see of "Dan GPS" actually now has this simplified transformation in the <mqttitude-coordinates.js> file :

result = "blablalocation";

So I'd expect to see "blablalocation" where the UI display "Dan GPS".  Here is the item description now:

String gps_string "prior to transform [%s]" <wind> (ALL) {mqtt="<[mymosquitto:owntracks/daniel/iphone5s:state:default]"}

String Location_Dan_Phone {mqtt="<[home:owntracks/daniel/iphone5s:state:JS(mqttitude-coordinates.js)]"}


It doesn't seem like my OpenHAB is using the js transform to interpret the results at all. 

Ben Jones

unread,
Jun 4, 2014, 9:57:22 PM6/4/14
to ope...@googlegroups.com
You are pointing to two different MQTT brokers, mymosquitto and home. Is that on purpose? Are your OwnTracks messages getting published to both brokers?

Scott K

unread,
Jun 4, 2014, 10:02:51 PM6/4/14
to ope...@googlegroups.com
Aha;lkwejr;lwakjre;lwkjer;wlkjre. 

You're right.  I copied and pasted too much.  This fixed all my issues.

Scott K

unread,
Jun 4, 2014, 10:12:14 PM6/4/14
to ope...@googlegroups.com
Thanks for all the help.

Odd thing:  On a browser on my computer, the map page shows up fine after I open the iFrame in a new tab and accept the certificate.

However, on the Android app, I get a "Webpage not available" error.  Even though it's going to the same page...<https://192.168.x.x:8443/static/map.html>


Reply all
Reply to author
Forward
0 new messages