Skip to content

Commit

Permalink
Add support for MQTT SSL (#140)
Browse files Browse the repository at this point in the history
* Add support for MQTT SSL

* Fixed format
  • Loading branch information
virtualm2000 authored and adriankumpf committed Sep 8, 2019
1 parent 9c61150 commit b1ffa97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/releases.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 19 additions & 7 deletions lib/teslamate/mqtt/mqtt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit b1ffa97

@virtualm2000
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works 100% with

export MQTT_TLS="true"
export MQTT_TLS_ACCEPT_INVALID_CERTS="true"

Thank you!

Best regards,
Mihai

Please sign in to comment.