[SOLVED] Problems plotting item on map

I am trying to plot the location (of the ISS) on a map for a mapview.
I have the latitude and longitude that I get as a string and I dfined the actual location as a Location item, like so:

String iss_lat "ISS latitude [%s]" <marker>  {http="<[iss:6000:JSONPATH($.iss_position.latitude)]"}
String iss_long "ISS longtitude [%s]" <marker>  {http="<[iss:6000:JSONPATH($.iss_position.longitude)]"}
Location iss_loc

those two string items show valid outcome in my UI
iss

Subsequently I am trying to convert the latitude and longitude to a location with the following rule:

rule iss
when
  Item iss_lat changed
then
  var PointType iss = new PointType("iss_lat,iss_long")
  iss_loc.postUpdate(iss)
end

then I show it in a map like this:

Mapview item=iss_loc height=10 label="ISS"

Sadly however, my rule is wrong (I adapted it from here https://community.openhab.org/t/location-item-example/5135/2)

My log says it returns ‘null’

When I use defined numbers rather than variables, like so:

var PointType iss = new PointType("52, 4.5")

then the mapview works perfectly.
So somewhere I guess there is a problem with my type conversion but I cant figure it out.
I tried PointType("iss_lat.state, iss_long.state") which has no effect, also result ‘null’

Anybody have some pointers for me?

You probably want the states i.e. iss_lat.state

Make sure your incoming numeric lat, long values don’t have blanks or other whitespace which could trip up number parsing.

Also, I mentored a group of kids a few months ago and we wrote a program that ran on the ISS, and in the course of things I found this way of calculating the position of the ISS over the earth, and you could feed this directly into openHAB without needing to scrape it off a website:

https://bitbucket.org/watou/coderdojo/src/d3908815b194496531d316bf420856ff59778267/astropi/data/findlocs.py?at=master&fileviewer=file-view-default

1 Like

Thanks @rossko57, but I already tried that, but you might have overlooked that in my reply.
I think the problem is that the PointType function expects two integers, while I feed it strings, but iss_lat.state.intValue gave an error.

@watou Thanks that crossed my mind, but as far as I can see there are no leading or trailing spaces.
I tried iss_long.state.trim but that generated the error: 'trim' is not a member of 'org.eclipse.smarthome.core.library.types.StringType'; I will definitely have a look at your code appreciate it, however my attempt was more for ‘practice’ within OH so I still will try to get this to work

The example you give that ‘works’ PointType(“52, 4.5”) is not being fed strings - it is being fed one string, which includes a comma.

You can reproduce that by concatenating a string from your two states + " , " between

PointType(iss_lat.state + " , " + iss_long.state")

EDIT - akk, erroneous " at end there

Thanks could be very right in that, then I don’t have to linger on string conversion anymore


 but then I really am at the end of my wits why it doesn’t work.

Wait
 you might be on to something

var PointType iss=new PointType(iss_lat.state + " , " + iss_long.state)

seems to work

Edit
For completeness sake let me give the full code:
http.cfg:
iss.url=http://api.open-notify.org/iss-now.json
irl.updateInterval=6000

Sitemap
Mapview item=iss_loc height=10 label="ISS"

Itemfile

String iss_lat "ISS latitude [%s]"  {http="<[iss:6000:JSONPATH($.iss_position.latitude)]"}
String iss_long "ISS longtitude [%s]"  {http="<[iss:6000:JSONPATH($.iss_position.longitude)]"}
Location iss_loc 

Rules file

rule iss
when
  Item iss_lat changed
then
var PointType iss=new PointType(iss_lat.state + " , " + iss_long.state)
iss_loc.postUpdate(iss)
end

Thanks for both your help @rossko57, @watou

1 Like