Quick Start
If available in Hex, the package can be installed as:
-
Add
busto your list of dependencies inmix.exs:
```elixir
def deps do
[{:bus, "~> 0.1.0"}]
end
```-
Ensure
busis started before your application:
```elixir
def application do
[applications: [:bus]]
end
```-
Add Configuration Details in
config.exfile.
```elixir
config :bus,
host: 'localhost',
port: 1883,
client_id: "1", #needs to be string.
keep_alive: 100,
username: "",
password: "",
auto_reconnect: true, #if client get disconnected, it will auto reconnect.
auto_connect: true, #this will make sure when you start :bus process, it gets connected autometically
callback: Bus.Callback #callback module, you need to implement callback inside.
```Publish
topic = "a" message = "Hello World...!" qos = 1 Bus.Mqtt.publish(topic,message,qos)Subscribe
topics = ["a","b","c"] #list of topics qoses = [1,0,2] #list of qos in same order as topics. Bus.Mqtt.subscribe(topics,qoses)Callback
```elixir
defmodule Bus.Callback do
def on_publish(data) do
IO.inspect data
end
def on_connect(data) do
IO.inspect data
end
def on_subscribe(data) do
IO.inspect data
end
def on_unsubscribe(data) do
IO.inspect data
end
def on_message_received(topic,message) do
IO.inspect topic
IO.inspect message
end
end
```
This still needs more improvements, may change in upcoming versions.Pure Mqtt client written in Elixir
Note
Detailed Documentation is coming soon.