From 3ff56db86a9d21aa85df2187ed7b736456314e42 Mon Sep 17 00:00:00 2001 From: virtualm Date: Tue, 3 Sep 2019 14:45:20 +0100 Subject: [PATCH 1/2] Add support for MQTT SSL --- config/releases.exs | 3 ++- lib/teslamate/mqtt/mqtt.ex | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/releases.exs b/config/releases.exs index 9915ca7c4a..00e9ed9388 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -36,7 +36,8 @@ if System.get_env("DISABLE_MQTT") != "true" do config :teslamate, :mqtt, host: System.fetch_env!("MQTT_HOST"), username: System.get_env("MQTT_USERNAME"), - password: System.get_env("MQTT_PASSWORD") + password: System.get_env("MQTT_PASSWORD"), + ssl: System.get_env("MQTT_SSL") end config :logger, diff --git a/lib/teslamate/mqtt/mqtt.ex b/lib/teslamate/mqtt/mqtt.ex index 0f05d91153..dbd6efeb8e 100644 --- a/lib/teslamate/mqtt/mqtt.ex +++ b/lib/teslamate/mqtt/mqtt.ex @@ -1,6 +1,6 @@ defmodule TeslaMate.Mqtt do use Supervisor - + alias __MODULE__.{Publisher, PubSub} # API @@ -26,7 +26,8 @@ defmodule TeslaMate.Mqtt do defp config do auth = Application.get_env(:teslamate, :mqtt) - + + if(Keyword.get(auth, :ssl)=="false") do [ user_name: Keyword.get(auth, :username), password: Keyword.get(auth, :password), @@ -34,6 +35,16 @@ defmodule TeslaMate.Mqtt do handler: {Tortoise.Handler.Logger, []}, subscriptions: [] ] + else + [ + user_name: Keyword.get(auth, :username), + password: Keyword.get(auth, :password), + server: {Tortoise.Transport.SSL, host: Keyword.get(auth, :host), port: 8883, verify: :verify_none}, + handler: {Tortoise.Handler.Logger, []}, + subscriptions: [] + ] + end + end defp generate_client_id do From 9cc71d3bbcf32828c366cd32a7892145ea90c1d2 Mon Sep 17 00:00:00 2001 From: virtualm Date: Tue, 3 Sep 2019 15:19:29 +0100 Subject: [PATCH 2/2] Fixed format --- lib/teslamate/mqtt/mqtt.ex | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/teslamate/mqtt/mqtt.ex b/lib/teslamate/mqtt/mqtt.ex index dbd6efeb8e..78ac4b3164 100644 --- a/lib/teslamate/mqtt/mqtt.ex +++ b/lib/teslamate/mqtt/mqtt.ex @@ -1,6 +1,6 @@ defmodule TeslaMate.Mqtt do use Supervisor - + alias __MODULE__.{Publisher, PubSub} # API @@ -26,25 +26,26 @@ defmodule TeslaMate.Mqtt do defp config do auth = Application.get_env(:teslamate, :mqtt) - - if(Keyword.get(auth, :ssl)=="false") do - [ - user_name: Keyword.get(auth, :username), - password: Keyword.get(auth, :password), - server: {Tortoise.Transport.Tcp, host: Keyword.get(auth, :host), port: 1883}, - handler: {Tortoise.Handler.Logger, []}, - subscriptions: [] - ] - else - [ - user_name: Keyword.get(auth, :username), - password: Keyword.get(auth, :password), - server: {Tortoise.Transport.SSL, host: Keyword.get(auth, :host), port: 8883, verify: :verify_none}, - handler: {Tortoise.Handler.Logger, []}, - subscriptions: [] - ] - end + if(Keyword.get(auth, :ssl) == "false") do + [ + user_name: Keyword.get(auth, :username), + password: Keyword.get(auth, :password), + server: {Tortoise.Transport.Tcp, host: Keyword.get(auth, :host), port: 1883}, + handler: {Tortoise.Handler.Logger, []}, + subscriptions: [] + ] + else + [ + user_name: Keyword.get(auth, :username), + password: Keyword.get(auth, :password), + server: + {Tortoise.Transport.SSL, + host: Keyword.get(auth, :host), port: 8883, verify: :verify_none}, + handler: {Tortoise.Handler.Logger, []}, + subscriptions: [] + ] + end end defp generate_client_id do