|
| 1 | +--- |
| 2 | +layout: page |
| 3 | +title: "OwnTracks with two MQTT brokers" |
| 4 | +description: "Setting up OwnTracks with 2 MQTT brokers bridged for use with the MQTT bridge for SmartThings." |
| 5 | +date: 2016-08-27 10:05 |
| 6 | +sidebar: true |
| 7 | +comments: false |
| 8 | +sharing: true |
| 9 | +footer: true |
| 10 | +ha_category: Infrastructure |
| 11 | +--- |
| 12 | + |
| 13 | +I ([surge919](https://github.com/surge919)) successfully tied in [OwnTracks](http://owntracks.org/) to Home Assistant and [SmartThings](https://www.smartthings.com/) while using authentication for external access. The MQTT bridge doesn't support authentication so I set up 2 MQTT instances. |
| 14 | + |
| 15 | +Here are the steps I performed. Hopefully it saves someone else some time. |
| 16 | + |
| 17 | +It seems to be working pretty well but if anyone sees something incorrect in my configuration, please let me know. This is my first real interaction with MQTT. |
| 18 | + |
| 19 | +Here's a summary of my setup: |
| 20 | + |
| 21 | +Two Docker instances for MQTT |
| 22 | + |
| 23 | +- 1 for internal use (the MQTT bridge for SmartThings - no authentication) |
| 24 | +- 1 for external use (for OwnTracks - with authentication) |
| 25 | + |
| 26 | +All Docker configuration files are on my NAS so the Docker containers can be destroyed without affecting my actual configuration files. |
| 27 | + |
| 28 | +#### Docker setup for the mosquitto internal instance. No authentication for use with the MQTT bridge. |
| 29 | + |
| 30 | +```bash |
| 31 | +$ docker run -ti -p 1883:1883 \ |
| 32 | + -v /volume1/data/mosquitto-int/config:/mqtt/config:ro \ |
| 33 | + -v /volume1/data/mosquitto-int/log:/mqtt/log \ |
| 34 | + -v /volume1/data/mosquitto-int/data/:/mqtt/data/ \ |
| 35 | + --name mosquitto-int -d toke/mosquitto |
| 36 | +``` |
| 37 | + |
| 38 | +#### Docker setup for the mosquitto external instance. With authentication for use with Owntracks. |
| 39 | + |
| 40 | +```bash |
| 41 | +$ docker run -ti -p 1884:1883 \ |
| 42 | + -v /volume1/data/mosquitto-ext/config:/mqtt/config:ro \ |
| 43 | + -v /volume1/data/mosquitto-ext/log:/mqtt/log \ |
| 44 | + -v /volume1/data/mosquitto-ext/data/:/mqtt/data/ \ |
| 45 | + -v /volume1/data/mosquitto-ext/etc:/etc/mosquitto \ |
| 46 | + --name mosquitto-ext -d toke/mosquitto |
| 47 | +``` |
| 48 | + |
| 49 | +Here are the config files: |
| 50 | + |
| 51 | +`/volume1/data/mosquitto-int/config/mosquitto.conf` |
| 52 | + |
| 53 | +```bash |
| 54 | +connection mosquitto-ext |
| 55 | +persistence_file mosquitto.db |
| 56 | +try_private true |
| 57 | +address 10.0.0.20:1884 |
| 58 | +start_type automatic |
| 59 | +sername test |
| 60 | +password test |
| 61 | +notifications true |
| 62 | +topic owntracks/# in |
| 63 | +log_type all |
| 64 | +log_dest file /mqtt/log/mqtt.log |
| 65 | +log_facility 5 |
| 66 | +``` |
| 67 | + |
| 68 | +`/volume1/data/mosquitto-ext/config/mosquitto.conf` |
| 69 | + |
| 70 | +```bash |
| 71 | +connection mosquitto-int |
| 72 | +persistence_file mosquitto.db |
| 73 | +try_private true |
| 74 | +address 10.0.0.20:1883 |
| 75 | +start_type automatic |
| 76 | +username test |
| 77 | +password test |
| 78 | +notifications true |
| 79 | +topic owntracks/# out |
| 80 | +log_type all |
| 81 | +log_dest file /mqtt/log/mqtt.log |
| 82 | +log_facility 5 |
| 83 | +allow_anonymous false |
| 84 | +password_file /etc/mosquitto/pwfile |
| 85 | +``` |
| 86 | + |
| 87 | +Create a password for `mosquitto-ext` |
| 88 | + |
| 89 | +```bash |
| 90 | +$ docker exec -it mosquitto-ext /bin/bash |
| 91 | +$ cd /etc/mosquitto/ |
| 92 | +$ mosquitto_passwd -c /etc/mosquitto/pwfile <userID> |
| 93 | +``` |
| 94 | + |
| 95 | +### OwnTracks settings for Android |
| 96 | + |
| 97 | +```bash |
| 98 | +Preferences / Connection / Mode - Private MQTT |
| 99 | + |
| 100 | +Fill out |
| 101 | + Host |
| 102 | + Identification |
| 103 | + Security: TLS disabled |
| 104 | +``` |
| 105 | + |
| 106 | +<img src="//community-home-assistant-assets.s3.amazonaws.com/original/2X/5/5ce27145e5b37bac72859e4c36b8269d14f85ce1.png" width="649" height="500"> |
0 commit comments