Connecting to AWS IOT mqtt

Tags: #<Tag:0x00007fbcb34664d8>


I’ve tried multiple mqtt clients and almost no one has ssl client support except exmqtt that wraps emqttc, using that I’ve tried to connect to aws iot using:

{:ok, pid} = Exmqttc.start_link(MqttClient, [], [
  host: '',
  port: 8883,
  clean_sess: true,
  ssl: [
    certfile: Application.app_dir(:dem, "priv/mqtt-certificate.pem.crt"),
    keyfile: Application.app_dir(:dem, "priv/mqtt-private.pem.crt")
  auto_resub: true,
  reconnect: true
], %{})
Exmqttc.subscribe(pid, "#")

however none of the connect/disconnect callbacks are called. My callbacks module is:

defmodule MqttClient do
  require Logger
  use Exmqttc.Callback

  def init(_params) do
    {:ok, []}

  def handle_connect(state) do
    Logger.debug "Connected"
    {:ok, state}

  def handle_disconnect(state) do
    Logger.debug "Disconnected"
    {:ok, state}

  def handle_publish(topic, payload, state) do
    Logger.debug "Message received on topic #{topic} with payload #{payload}"
    {:ok, state}

does someone have any idea? Is my elixir config correct? (specially the ssl part which I’m not sure is the right elixir counterpart of the erlang code)


I haven’t tried connecting to a amazon hosted MQTT server, but I do have a client called Tortoise, and it does support SSL. Currently it lacks documentation, and I am about to write some; have you tried it? What’s your experience? Where should I focus in the documentation?

I was thinking I should make a “guides” section in the documentation where topics such as connecting to AWS hosted MQTT could be described.


Thanks for the reply, I went through tortoise but without any doc and since I was in a hurry I’ve just used gen_mqtt (which is also yours :slight_smile:) with mosquitto which bridges the client to AWS IOT.

Btw regarding documentation a non-ssl/ssl and an handler example (just saw that in the tests) would be more than enough!


Awesome. Perhaps I should write a macro that will make implementing a Tortoise.Handler easier with default implementations for most of the callbacks. Currently I am making an attempt to improve the documentation for Tortoise over at this pull request:

Don’t be shy if you have any feedback.