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..78ac4b3164 100644 --- a/lib/teslamate/mqtt/mqtt.ex +++ b/lib/teslamate/mqtt/mqtt.ex @@ -27,13 +27,25 @@ defmodule TeslaMate.Mqtt do defp config do auth = Application.get_env(:teslamate, :mqtt) - [ - 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: [] - ] + 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