exmqttc v0.4.1 Exmqttc

Exmqttc provides a connection to a MQTT server based on emqttc

Link to this section Summary

Types

A PID like type

A QoS level

A single topic, a list of topics or a list of tuples of topic and QoS level

Functions

Disconnect socket from MQTT server

Publish a message to MQTT. opts is a keywordlist and supports :retain with a boolean and :qos with an integer from 1 to 3

Start the Exmqttc client. callback_module is used for callbacks and should implement the Exmqttc.Callback behaviour. opts are passed directly to GenServer. mqtt_opts are reformatted so all options can be passed in as a Keyworld list

Subscribe to the given topic(s) given as topics with a given qos

Publish a message to MQTT synchronously. opts is a keywordlist and supports :retain with a boolean and :qos with an integer from 1 to 3

Subscribe to the given topics while blocking until the subscribtion has been confirmed by the server

Link to this section Types

Link to this type pidlike()
pidlike() :: pid | port | atom | {atom, node}

A PID like type

Link to this type qos()
qos() :: :qos0 | :qos1 | :qos2

A QoS level

Link to this type topics()
topics() :: String.t | [String.t] | [{String.t, qos}]

A single topic, a list of topics or a list of tuples of topic and QoS level

Link to this section Functions

Link to this function disconnect(pid)
disconnect(pid) :: :ok

Disconnect socket from MQTT server

Link to this function publish(pid, topic, payload, opts \\ [])
publish(pid, binary, binary, list) :: :ok

Publish a message to MQTT. opts is a keywordlist and supports :retain with a boolean and :qos with an integer from 1 to 3

Link to this function start_link(callback_module, opts \\ [], mqtt_opts \\ [])

Start the Exmqttc client. callback_module is used for callbacks and should implement the Exmqttc.Callback behaviour. opts are passed directly to GenServer. mqtt_opts are reformatted so all options can be passed in as a Keyworld list.

mqtt_opts supports the following options:

  • host: Connection host, charlist, default: 'localhost'
  • port: Connection port, integer, default 1883
  • client_id: Binary ID for client, automatically set to UUID if not specified
  • clean_sess: MQTT cleanSession flag. true disables persistent sessions on the server
  • keepalive: Keepalive timer, integer
  • username: Login username, binary
  • password: Login password, binary
  • will: Last will, keywordlist, sample: [qos: 1, retain: false, topic: "WillTopic", payload: "I died"]
  • connack_timeout: Timeout for connack package, integer, default 60
  • puback_timeout: Timeout for puback package, integer, default 8
  • suback_timeout: Timeout for suback package, integer, default 4
  • ssl: List of ssl options
  • auto_resub: Automatically resubscribe to topics, boolean, default: false
  • reconnect: Automatically reconnect on lost connection, integer (), default false
Link to this function subscribe(pid, topics, qos \\ :qos0)
subscribe(pidlike, topics, qos) :: :ok

Subscribe to the given topic(s) given as topics with a given qos.

Link to this function sync_publish(pid, topic, payload, opts \\ [])
sync_publish(pid, binary, binary, list) :: :ok

Publish a message to MQTT synchronously. opts is a keywordlist and supports :retain with a boolean and :qos with an integer from 1 to 3

Link to this function sync_subscribe(pid, topics)
sync_subscribe(pid, topics) :: :ok

Subscribe to the given topics while blocking until the subscribtion has been confirmed by the server.