Basic stuff?

  • Platform information:
    • Hardware: Intel 4th gen i5
    • OS: Ubuntu 18.04 LTS
    • Java Runtime Environment: zulu-8
    • openHAB version: 2.5.3

I setup a VM with a new fresh installation, added the MQTT broker and connected it to my routers MQTT server using its IP address… or so I tought. Apparently you can not use an IP address as I found this in the log:

MqttBroker connection configuration faulty: ID segment ‘10.0
.1.1’ contains invalid characters. Each segment of the ID must match the pattern [A-Za-z0-9_-]*.

You can guess why I was stumped as the input field clearly states “Hostname or IP of the broker.”

Obviously this is due to me not inputting a name as it stated: “If nothing is set, an automatic name based on the host and port will be generated.”

Problem one “solved”, but this needs a fix.

Anyway now I’m at problem two, I have OwnTracks on my phone reporting to my MQTT server on owntracks/username/devices and the following string is published:

{"_type":“location”,“acc”:16,“alt”:45,“batt”:96,“conn”:“w”,“lat”:53.2457576,“lon”:6.6573844,“tid”:“0”,“tst”:1586049211,“vac”:32,“vel”:0}

Using the “Generic MQTT Thing” I want to use its location, but the location thingy requires the following format: lat, lon, alt

If use jsonpath.com with “$.lat,lon,alt” it outputs the correct values, but the openhab.log tells me differently:

Executing the JSONPATH-transformation failed: Invalid path ’
$.lat,lon,alt’ in ‘{"_type":“location”,“acc”:16,“alt”:39,“batt”:100,“conn”:“w”,“lat”:53.2457549,“lon”:6.6573816,“tid”:“0”,“tst”:15860
52042,“vac”:128,“vel”:0}’

How would one extract the required data? Obviously outputting single values with “$.lat” works, but no map…

Your IP works without Problems (i’m also at OH 2.5.3) can you post a screenshot of your error?
image

And for the JSON:
$.lat,lon,alt will returnn an array, however if I read the documentation about the JSON transformation, it states

You could extract multiple chunks of a JSON message and combine into a single string (comma seperated list required, according to docs) with a JS javascript transformation.

This is the error I get in openhab.log when I only input an IP address.

I think its just a silly oversight on how the ID is generated, surely Im not the only one using IP addresses…

I’ll mess around with a JS transformation, I read about it yesterday and it makes more sense to do it that way.

I solved the lat, lon, alt problem this way if anyone ever bumps his toe on it:

(function(x)
{
        var json = JSON.parse(x);

        return json.lat + ", " + json.lon + ", " + json.alt;
})(input)

The location thing probably needs GeoID added to it to translate height, worry for another day :slight_smile:

2 Likes

OK, didn’t know that you are using the integrated broker.
What i’ve posted above was the bridge configuration to connect to another broker.
But if your configuration only works with a hostname and no IP, you could file a report here:

For me it looks like a bug.

Br
Sascha

A search for your error message threw up -

I understand what the error means, I think its a bug as well as this string should be sanitized before use and will report it!

If you read the other thread, there is absolutely nothing stopping you from putting your IP address in the IP box, which is what we started with.
But it seems you must then specify a valid ID and not let it try to default.

1 Like