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
-
Mqtt events.
Type:
- string
Properties:
Name Type Default Description CONNECTstring connect MESSAGEstring message CLOSEstring close ENDstring end
Methods
-
connect( [callback])
-
Creates a new connection to the bus.
Parameters:
Name Type Argument Description callbackfunction <optional>
Returns:
- Type
- olympe.net.Mqtt
-
end( [force] [, callback])
-
Closes the client.
Parameters:
Name Type Argument Description forceboolean <optional>
passing it to true will close the client right away, without waiting for the in-flight messages to be acked. Optional
callbackfunction <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 callbackfunction 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 topicstring the topic on which we will publish the message
messageObject the message
optionsolympe.net.Mqtt.PublishOptions <optional>
the publish options
callbackfunction <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 topicstring the topic to subscribe to
callbackfunction 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 topicstring the topic to unsubscribe from
callbackfunction <optional>
the callback to invoke when the unsubscription is complete. Optional
Returns:
- Type
- olympe.net.Mqtt
Type Definitions
-
MQTTConnectionOptions
-
Mqtt connection options.
Type:
- Object
Properties:
Name Type Description wsOptionsolympe.net.Mqtt.WSOptions is the WebSocket connection options. Default is {}. It's specific for WebSockets
keepalivenumber 60 seconds, set to 0 to disable
reschedulePingsboolean reschedule ping messages after sending packets (default true)
clientIdstring 'mqttjs_' + Math.random().toString(16).substr(2, 8)
cleanboolean true, set to false to receive QoS 1 and 2 messages while offline
reconnectPeriodnumber 1000 milliseconds, interval between two reconnections. Disable auto reconnect by setting to 0.
connectTimeoutnumber 30 * 1000 milliseconds, time to wait before a CONNACK is received
usernamestring the username required by your bus, if any
passwordstring the password required by your bus, if any
queueQoSZeroboolean if connection is broken, queue outgoing QoS zero messages (default true)
-
PublishOptions
-
Publish options.
Type:
- Object
Properties:
Name Type Description qosnumber QoS level, Number, default 0
retainboolean retain flag, default false
dupboolean mark as duplicate flag, default false
-
WSOptions
-
WebSocket connection options.
Type:
- Object
Properties:
Name Type Description followRedirectsboolean Whether or not to follow redirects. Defaults to false.
handshakeTimeoutnumber Timeout in milliseconds for the handshake request. This is reset after every redirection.
maxRedirectsnumber The maximum number of redirects allowed. Defaults to 10.
perMessageDeflateboolean | Object Enable/disable permessage-deflate.
protocolVersionnumber Value of the Sec-WebSocket-Version header.
originstring Value of the Origin or Sec-WebSocket-Origin header depending on the protocolVersion.
maxPayloadnumber The maximum allowed message size in bytes.
Olympe SDK