new Mqtt(url [, options])
Creates an instance of a MQTT client.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
url |
string | the url for bus connection |
|
options |
olympe.net.Mqtt.MQTTConnectionOptions |
<optional> |
the connection options |
Members
-
<static> Events :string
Methods
-
connect( [callback])
-
Creates a new connection to the bus.
Parameters:
Name Type Argument Description callback
function <optional>
Returns:
- Type
- olympe.net.Mqtt
-
end( [force] [, callback])
-
Closes the client.
Parameters:
Name Type Argument Description force
boolean <optional>
passing it to true will close the client right away, without waiting for the in-flight messages to be acked. Optional
callback
function <optional>
will be called when the client is closed. Optional
Returns:
- Type
- olympe.net.Mqtt
-
isConnected()
-
Checks if the client is connected to the bus.
Returns:
- Type
- boolean
-
onClose(callback)
-
Registers a callback to be invoked on connection closed.
Parameters:
Name Type Description callback
function the callback to invoke
Returns:
- Type
- olympe.net.Mqtt
-
publish(topic, message [, options] [, callback])
-
Publishes a message to the given topic.
Parameters:
Name Type Argument Description topic
string the topic on which we will publish the message
message
Object the message
options
olympe.net.Mqtt.PublishOptions <optional>
the publish options
callback
function <optional>
the callback to invoke once the message is published
Returns:
- Type
- olympe.net.Mqtt
-
subscribe(topic, callback)
-
Subscribes to the given topic and starts receiving messages.
Parameters:
Name Type Description topic
string the topic to subscribe to
callback
function the callback to invoke when a message is received from the given topic
Returns:
- Type
- olympe.net.Mqtt
-
unsubscribe(topic [, callback])
-
Unsubscribes from the given topic.
Parameters:
Name Type Argument Description topic
string the topic to unsubscribe from
callback
function <optional>
the callback to invoke when the unsubscription is complete. Optional
Returns:
- Type
- olympe.net.Mqtt
Type Definitions
-
MQTTConnectionOptions
-
PublishOptions
-
WSOptions