Skip to content

narslan/mqttc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mqttc

A fast and robust ** MQTT v5 client** for Elixir.
It aims to provide a reliable MQTT client with a simple user-facing API.

Features

  • Interface for sending MQTT v5 support (CONNECT, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PING, DISCONNECT).
  • Automatic Reconnections
  • SSL
  • Telemetry support

Installation

Add mqttc to your dependencies in mix.exs:

def deps do
  [
    {:mqttc, "~> 0.2"}
  ]
end

Usage:

# Connect
{:ok, pid} = Mqttc.start_link(host: "test.mosquitto.org", port: 1883)
# or Start connection and wait until CONNACK received.  
{:ok, pid} = Mqttc.start_link_sync(host: "test.mosquitto.org", port: 1883)


# Subscribe to topics with handlers
Mqttc.subscribe(pid, [
  {"sensors/temp", fn msg -> IO.inspect(msg, label: "Temperature") end},
  {"sensors/humidity", fn msg -> IO.inspect(msg, label: "Humidity") end}
])

# Publish 
Mqttc.publish(pid, "sensors/temp", "25°C")

# Unsubscribe
Mqttc.unsubscribe(pid, "sensors/humidity")

# Disconnect
Mqttc.disconnect(pid)

Authenticate and connect:

{:ok, pid} =  Mqttc.start_link_sync( host: "test.mosquitto.org", port: 1884, username: "rw", password: "readwrite" )

Usage with ssl:

{:ok, pid} = Mqttc.start_link(host: "broker.hivemq.com", port: 8883, ssl: true, ssl_opts: [  verify: :verify_peer, cacerts: :public_key.cacerts_get()])

License

Mqttc is released under the MIT license. See the license file.

About

Elixir MQTT v5 Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages