Copyright | (c) Dustin Sallings 2019 |
---|---|
License | BSD3 |
Maintainer | dustin@spy.net |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
An MQTT protocol client, based on the 3.1.1 specification: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
Synopsis
- data MQTTConfig = MQTTConfig {}
- data MQTTClient
- data QoS
- type Topic = Text
- mqttConfig :: MQTTConfig
- mkLWT :: Topic -> ByteString -> Bool -> LastWill
- data LastWill = LastWill {
- _willRetain :: Bool
- _willQoS :: QoS
- _willTopic :: ByteString
- _willMsg :: ByteString
- runClient :: MQTTConfig -> IO MQTTClient
- runClientTLS :: MQTTConfig -> IO MQTTClient
- waitForClient :: MQTTClient -> IO (Either SomeException ())
- connectURI :: MQTTConfig -> URI -> IO MQTTClient
- disconnect :: MQTTClient -> IO ()
- subscribe :: MQTTClient -> [(Topic, QoS)] -> IO [Maybe QoS]
- unsubscribe :: MQTTClient -> [Topic] -> IO ()
- publish :: MQTTClient -> Topic -> ByteString -> Bool -> IO ()
- publishq :: MQTTClient -> Topic -> ByteString -> Bool -> QoS -> IO ()
Configuring the client.
data MQTTConfig Source #
Configuration for setting up an MQTT client.
MQTTConfig | |
|
data MQTTClient Source #
The MQTT client. A client may be built using either runClient or runClientTLS. For example:
mc <- runClient mqttConfig{} publish mc "some/topic" "some message" False
QoS values for publishing and subscribing.
mqttConfig :: MQTTConfig Source #
A default MQTTConfig. A _connID should be provided by the client in the returned config, but the defaults should work for testing.
mkLWT :: Topic -> ByteString -> Bool -> LastWill Source #
A convenience method for creating a LastWill.
An MQTT Will message.
LastWill | |
|
Running and waiting for the client.
runClient :: MQTTConfig -> IO MQTTClient Source #
Set up and run a client from the given config.
runClientTLS :: MQTTConfig -> IO MQTTClient Source #
Set up and run a client connected via TLS.
waitForClient :: MQTTClient -> IO (Either SomeException ()) Source #
Wait for a client to terminate its connection.
connectURI :: MQTTConfig -> URI -> IO MQTTClient Source #
Connect to an MQTT server by URI. Currently only mqtt and mqtts URLs are supported. The host, port, username, and password will be derived from the URI and the values supplied in the config will be ignored.
disconnect :: MQTTClient -> IO () Source #
Disconnect from the MQTT server.
General client interactions.
subscribe :: MQTTClient -> [(Topic, QoS)] -> IO [Maybe QoS] Source #
Subscribe to a list of topics with their respective QoSes. The accepted QoSes are returned in the same order as requested.
unsubscribe :: MQTTClient -> [Topic] -> IO () Source #
Unsubscribe from a list of topics.
:: MQTTClient | |
-> Topic | Topic |
-> ByteString | Message body |
-> Bool | Retain flag |
-> IO () |
Publish a message (QoS 0).
:: MQTTClient | |
-> Topic | Topic |
-> ByteString | Message body |
-> Bool | Retain flag |
-> QoS | QoS |
-> IO () |
Publish a message with the specified QoS.