mqtt-tools / mqttwarn

A highly configurable MQTT message router, where the routing targets are notification plugins, primarily written in Python.
https://mqttwarn.readthedocs.io/
Eclipse Public License 2.0
958 stars 184 forks source link

Request for an example cfg showing how to connect mqttwarn to hosted owntracks #153

Closed dazzag24 closed 8 years ago

dazzag24 commented 9 years ago

Would it be possible to add a sample config, or to document how to point mqttwarn to the owntracks hosted MQTT server at https://hosted.owntracks.org?

Thanks

jpmens commented 9 years ago

Please explain what you are trying to do: we provided "Hosted" for our OwnTracks location apps basically. Why do you need to connect mqttwarn?

dazzag24 commented 9 years ago

Hi,

Maybe I'm misunderstanding something, but here is what I thought:

I'm using owntrack Android on two phones pointing to the hosted owntracks broker.

I have pointed owntracks/recorder at this hosted broker so that I can have map based UI to show tracks and last location.

I am no interested in investigating some of the mqttwarn features (in particular the pushover.net integration), but I cannot figure out how to point the ini file at the hosted mqtt server. In particular I think the tls/pem cert will be tricky.

Am I barking up the wrong tree? or just not explained myself clearly in the original question?

Thanks in advance.

dazzag24 commented 9 years ago

So I want to received events from hosted mqtt NOT post them to it. Make sense?

jpmens commented 9 years ago

This page has the details you need in terms of username, password, and the TLS root certificate you will require.

dazzag24 commented 9 years ago

Thanks. I have used the sample python program already so I know that it does work with hosted.owntracks.org.

However, while I can figure out what I need to enter for the host, username and port, it isn't clear how I can replicate the tls settings that the python example program uses:

client.tls_set('/path/to/ca-bundle.pem', cert_reqs=ssl.CERT_REQUIRED)

Using some inspiration from this cached google result: http://webcache.googleusercontent.com/search?q=cache:fk70a9D-k30J:jameswhale.net/mqttwarn/mqttwarn.conf+&cd=4&hl=en&ct=clnk&gl=uk

I think I need to see these settings in the [default] section of the ini file

ca_certs = '/path/to/ca-certs.pem' tls_insecure = False

However I cannot see anyway of passing in the "cert_reqs=ssl.CERT_REQUIRED" parameter. Not without editing the mqttwarn code in any case. These param presumably get passed down into connect() and hence to line 842:

if cf.tls == True: mqttc.tls_set(cf.ca_certs, cf.certfile, cf.keyfile, tls_version=cf.tls_version, ciphers=None)

Will it work if I emit the "cert_reqs" parameter and only set the "ca_certs" parameter?

dazzag24 commented 9 years ago

In addition what protocol is required?

In the exmaple python the mqtt client is instantiated like this:

client = mqtt.Client(clientid)

whereas in mqttwarn it is done like so

mqttc = paho.Client(cf.clientid, clean_session=cf.cleansession, protocol=cf.protocol)

It isn't clear from the http://owntracks.org/booklet/tech/proghosted/ page which protocol hosted owntracks is using.

jpmens commented 9 years ago

Have you tried it? Just set ca_certs and tls_insecure = False; that should do it.

dazzag24 commented 9 years ago

I'll give it a go. Only able to test at home. http proxy prevents me testing at work

dazzag24 commented 9 years ago

mqttwarn.log: 2015-11-10 20:22:00,723 INFO [mqttwarn] Starting mqttwarn 2015-11-10 20:22:00,723 INFO [mqttwarn] INFO MODE 2015-11-10 20:22:00,724 DEBUG [mqttwarn] DEBUG MODE 2015-11-10 20:22:00,725 DEBUG [mqttwarn] Service file loaded 2015-11-10 20:22:00,726 DEBUG [mqttwarn] Service log loaded 2015-11-10 20:22:00,726 DEBUG [mqttwarn] Attempting connection to MQTT broker hosted-mqtt.owntracks.org:8883... 2015-11-10 20:22:00,726 DEBUG [mqttwarn] Setting LWT to clients/mqttwarn... 2015-11-10 20:22:00,796 ERROR [mqttwarn] Cannot connect to MQTT broker at hosted-mqtt.owntracks.org:8883: an integer is required

mqttwarn.ini

[defaults] hostname = 'hosted-mqtt.owntracks.org' ; default port = 8883 username = 'xxxxx|Phone' password = 'xxxxxxxxxxx' clientid = 'mqttwarn' lwt = 'clients/mqttwarn' tls_insecure = False tls = True ca_certs = '/home/xxxxx/code/mqttwarn/ca-bundle.pem' skipretained = False cleansession = False protocol = 3

dazzag24 commented 9 years ago

Looks like it also need this line: tls_version = 'tlsv1'