package mqtt
Install
Dune Dependency
Authors
Maintainers
Sources
md5=1af0b40f0d73e2ed69b515a7c43d2e5f
sha512=f2640262b929bece15b51abd3bfcd708eb495fb7371c23e30c2a69f12a1633385d8de90153ee11aaeacb71b3f782f59b3a2f1ce9d783b20c959d9ce6f2f9d96a
doc/mqtt.client/Mqtt_client/index.html
Module Mqtt_client
Source
Represents an MQTT client.
To create a new client use Mqtt_client.connect
.
Client authentication credentials.
MQTT supports two authentication methods: username with password, or username only.
The credentials will be sent in plain text, unless TLS is used. See connection options for more information.
Client error & exceptions
Defines the exceptions raised by the client
Quality of Service level.
Defines the guarantee of delivery for messages.
val connect :
?id:string ->
?tls_ca:string ->
?credentials:credentials ->
?will:(string * string) ->
?clean_session:bool ->
?keep_alive:int ->
?on_message:(topic:string -> string -> unit Lwt.t) ->
?on_disconnect:(t -> unit Lwt.t) ->
?on_error:(t -> exn -> unit Lwt.t) ->
?port:int ->
string list ->
t Lwt.t
Connects to the MQTT broker.
Multiple hosts can be provided in case the broker supports failover. The client will attempt to connect to each one of hosts sequentially until one of them is successful.
on_error
can be provided to handle errors during client's execution. By default all internal exceptions will be raised with Lwt.fail
.
Note: Reconnection logic is not implemented currently.
let broker_hosts = [ ("host-1", "host-2") ] in
let on_message ~topic payload =
Lwt.printlf "topic=%S payload=%S" topic payload
in
Mqtt_client.connect ~id:"my-client" ~port:1883 ~on_message broker_hosts
|> Lwt_main.run
Disconnects the client from the MQTT broker.
let%lwt () = Mqtt_client.disconnect client