Mosquitto with owntracks and google map v3

Hi there!

I’ve just been starting with openhab on my raspberry pi 2. Got some kaku lights configured and am now trying to get openhab and mosquitto to work with owntracks. For testing i also have a openhab configuration on my Windows pc for faster rebooting and testing. I use the same config on both machines (besides one is on windows 10 and the other is on raspian lite)

When i start openhab on the windows machine and watch the logging i see:

2016-02-24 19:34:16.812 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto' 2016-02-24 19:34:17.006 [INFO ] [runtime.busevents ] - mqttPositionPatrikRaw state updated to {"_type":"location","lat":52.8942828,"lon":4.6107639,"tst":1456338327,"acc":26,"batt":88,"tid":"ik"}

But when i start openhab on the pi it just starts the connection.

2016-02-24 19:33:04.295 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

I think i might mis a package or something on the pi (raspian lite) but just cant figure out what it might be. My configuration is an exact copy of the Use Google MAP V3 API i found on github with a remote mosquitto broker. Any help or direction would me appriciated.

Which machine, Windows or Pi, is running the mosquitto broker? If your two systems have identical configs, which broker is your OwnTracks app pointing to?

The broker runs externaly. I got a vps on the internet i configured with the broker. Both pi and windows connect externaly. And owntracks app also connects to that server.

Can you install and run mosquitto_sub on the Pi to see if it can subscribe to topics from the same broker? If it works, then you can most likely rule out basic connectivity issues. Are you running the same or recent Java runtimes on both machines?

I just tested the connection. i’m not quite sure what i’m doing since i’m verry new to mosquitto. the command i used is:

mosquitto_sub -h <external.server.adres> -p 8883 -q 1 -i mosquitto -t ownctracks/user/mobile --cafile /home/pi/ca.crt --insecure -u mqtt -P <pwd> --insecure --tls-version tlsv1

Feb 25 08:43:01 isp01 mosquitto: 1456386181: New client connected from my.ip.adres as mosquitto (c1, k60, u'mqtt')

i do need to specify the ca.crt when connection from the pi cli to the external server. but i dont recall specifying the ca.crt in openhab. still both pi and windows do connect and seem to subscribe and windows can even get the “payload” (if that is the correct term)

Java on the pi:
openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b04)
OpenJDK Zero VM (build 25.40-b08, interpreted mode)

Java on windows:
java version "1.8.0_73"
Java™ SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot™ 64-Bit Server VM (build 25.73-b02, mixed mode)

I strongly recommend that you install and use the Oracle JDK instead of OpenJDK. This info might be helpful.

I just installed the Oracle JDK. Tnx for that. I now have a 25% performance increase! :slight_smile: openhab starts much faster and java uses less cpu, so thanks for that! The mosquitto setup still doesnt work. Maybe i’m making my setup to complex since i’m new to both openhab and mosquitto. I’m going to install the broker on the pi now to see if i can get it to work. I’ll report back with the results.

I wonder if having two MQTT clients with the same client ID is confusing the broker? What do the two openhab.cfg files look like for all mqtt:xxx=yyy values (of course redacting the private bits)?

Yeah you’re right about using the same client id is confusing for the broker. I have to stop the pi when starting the windows openhab and vise versa. If i dont stop one ot the two the logging shows something like closing old connection and starting new connection for as soon as one of the to starts asking for the payload.

So now i have the broker on the pi. Same issue. Below is first the Windows openhag.log with mosquitto.log and below that Pi openhab.log with mosquitto.log On windows it works like i would suspect. But on the pi (in the openhab.log) i just don’t see the location information.

WINDOWS

openhab.log
osgi> 2016-02-26 11:28:18.820 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.8.1).
2016-02-26 11:28:19.391 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2016-02-26 11:28:19.460 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2016-02-26 11:28:19.475 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-02-26 11:28:19.475 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2016-02-26 11:28:20.653 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2016-02-26 11:28:29.179 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.sitemap’
2016-02-26 11:28:29.279 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.items’
2016-02-26 11:28:29.713 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /classicui/openhab.app
2016-02-26 11:28:33.603 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampOranje bound to device LampOranje
2016-02-26 11:28:33.619 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampZwart1 bound to device LampZwart1
2016-02-26 11:28:33.634 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampZwart2 bound to device LampZwart2
2016-02-26 11:28:33.634 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampWoonKmr bound to device LampWoonKmr
2016-02-26 11:28:33.703 [ERROR] [io.gpio.internal.GPIOActivator] - No supported operating system was found, GPIO service won’t be available
2016-02-26 11:28:33.735 [INFO ] [runtime.busevents ] - mqttPositionPatrikRaw state updated to {"_type":“location”,“lat”:52.9308486,“lon”:4.413885,“tst”:1456481400,“acc”:60,“batt”:88,“tid”:“ik”}
2016-02-26 11:28:33.754 [INFO ] [.service.AbstractActiveService] - NetworkHealth Refresh Service has been started
2016-02-26 11:28:39.355 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model ‘home.rules’

mosquitto.log
1456482414: New connection from 192.168.x.x on port 8883.
1456482414: New client connected from 192.168.x.x as mosquitto (c1, k60, u’mqtt’).
1456482414: Sending CONNACK to mosquitto (0, 0)
1456482428: Received SUBSCRIBE from mosquitto
1456482428: owntracks/mqtt/gsmerik (QoS 1)
1456482428: mosquitto 1 owntracks/mqtt/gsmerik
1456482428: Sending SUBACK to mosquitto
1456482428: Sending PUBLISH to mosquitto (d0, q1, r1, m1, ‘owntracks/mqtt/gsmerik’, … (99 bytes))
1456482428: Received PUBACK from mosquitto (Mid: 1)
1456482488: Received PINGREQ from mosquitto

PI

openhab.log
2016-02-26 11:16:43.268 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.8.1).
2016-02-26 11:17:08.874 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2016-02-26 11:17:10.077 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2016-02-26 11:17:10.392 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-02-26 11:17:10.421 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2016-02-26 11:17:23.365 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.items’
2016-02-26 11:17:44.379 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.sitemap’
2016-02-26 11:18:09.200 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2016-02-26 11:18:15.972 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /classicui/openhab.app
2016-02-26 11:18:33.071 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.rules’
2016-02-26 11:18:39.059 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampOranje bound to device LampOranje
2016-02-26 11:18:39.071 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampZwart1 bound to device LampZwart1
2016-02-26 11:18:39.084 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampZwart2 bound to device LampZwart2
2016-02-26 11:18:39.096 [INFO ] [.PilightGenericBindingProvider] - pilight:kaku item LampWoonKmr bound to device LampWoonKmr
2016-02-26 11:18:46.349 [INFO ] [.service.AbstractActiveService] - NetworkHealth Refresh Service has been started
2016-02-26 11:18:48.467 [INFO ] [.b.p.internal.PilightConnector] - Established connection to pilight server at 127.0.0.1:5000

mosquitto.log
1456481832: New connection from 192.168.x.x on port 8883.
1456481834: New client connected from 192.168.x.x as mosquitto (c1, k60, u’mqtt’).
1456481834: Sending CONNACK to mosquitto (0, 0)
1456481894: Received PINGREQ from mosquitto
1456481894: Sending PINGRESP to mosquitto
1456481920: Received SUBSCRIBE from mosquitto
1456481920: owntracks/mqtt/gsmerik (QoS 1)
1456481920: mosquitto 1 owntracks/mqtt/gsmerik
1456481920: Sending SUBACK to mosquitto
1456481920: Sending PUBLISH to mosquitto (d0, q1, r1, m1, ‘owntracks/mqtt/gsmerik’, … (99 bytes))
1456481920: Received PUBACK from mosquitto (Mid: 1)
1456481980: Received PINGREQ from mosquitto
1456481980: Sending PINGRESP to mosquitto
1456482004: Socket error on client mqtt/gsmerik, disconnecting.
1456482004: Sending PUBLISH to mosquitto (d0, q0, r0, m0, ‘owntracks/mqtt/gsmerik’, … (32 bytes))
1456482040: Received PINGREQ from mosquitto
1456482040: Sending PINGRESP to mosquitto

openhab.cfg

mqtt:mosquitto.url=ssl://192.168.x.x:8883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqtt:mosquitto.clientId=mosquitto

# Optional. User id to authenticate with the broker.
mqtt:mosquitto.user=mqtt

# Optional. Password to authenticate with the broker.
mqtt:mosquitto.pwd=mqtt

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
mqtt:mosquitto.qos=1

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
mqtt:mosquitto.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
mqtt:mosquitto.async=false

What happens when you simply don’t specify mqtt:mosquitto.clientId in openhab.cfg on both Windows and Pi, so openHAB will generate its own? Do you need to specify a clientId for a reason?

Also, is there a reason why you are using the non-default settings for async and qos?

And to make it al complete;

mosquitto.conf

pid_file /var/run/mosquitto.pid

user mosquitto
bind_address 0.0.0.0
port 8883
cafile /etc/mosquitto/certs/ca.crt
# capath /etc/mosquitto/certs
certfile /etc/mosquitto/certs/pi.crt
keyfile /etc/mosquitto/certs/pi.key
# tls_version tlsv1
allow_anonymous false
password_file /etc/mosquitto/pwfile

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log
log_type all

include_dir /etc/mosquitto/conf.d

The settings for async and qos i found on an other forum i gues. Just did the copy/paste :slight_smile: i changed it to default settings now. also the mqtt:mosquitto.clientId is default now and generates its own id. Just to be clear, my problem isnt that i cant use both windows and pi at the same time. I just use windows for faster testing (core i7 vs pi) windows returns my location in the openhab.log and the pi isnt what makes me think my pi location check isnt working.

Could it be that it just doesnt show it in the pi logging? Is there a way to print or echo the location variable somewere in the openhab gui? It might be in ‘mqttPositionPatrikRaw’ right?

Just to update this issue. I think windows and linux read the home.rules a bit different. To make the file a bit more -h i added a blank line at the top. I think linux doesnt like that and windows doesnt care. Beside that i had 1 .rules file with multiple rules. Now i created separate files for the different rules. Now i at least see error messages in the openhab.log so i know the rules are used.

Thanks for the support so far! When i get everyting to work i will let you know.

Well thats quick. Its all working now. I see my location on the map. i only get an accuracy error but thats not important for now. So the sepperate rule files without blank lines did the trick. Beside that there seems to be some different logging in windows and linux. as i wrote before, in the openhab.log on windows i see more (lat / lon) information. raspbian openhab.log is just more clean i gues.

Except in very rare cases, logging on different OSs should be about the same in what is output. Are there differences in the file logback.xml on the two systems?

no the files are the same on both systems. but since it its working and openhab starts much quicker with the oracle java on the pi i will leave it at that and stop using the windows version :slight_smile: i have my lon/lat info and all works like a charm now. tnx for your support!!

1 Like