MQTTClient.disconnect()

Overview

Causes the MQTTClient object to disconnect.

Added in version 2.1.13

Format

var mqttClient = new MQTTClient(options);

mqttClient.disconnect(onComplete, onError);

Value Description Type Required Notes
onComplete A callback function that is called asynchronously if the connection completes. Function Optional When called, the first parameter is an empty object.
onError A callback function that is called asynchronously if the connection errors. Function Optional When called, the first parameter is a Error object as described below.

Error object properties

Value Description Type

Notes

message A message that describes the failure. String May be undefined.
type A category for the type of failure. String  

Example

Copy
/* Connect, send a message, and disconnect
 */

mqttClient = new MQTTClient({
    broker: "mqtt://mymqtt.example.com"
});

mqttClient.connect(function() {
    mqttClient.publish({
        topic: "this/is/a/test",
        payload: "tada"
    }, function(complete) {
        mqttClient.disconnect();
    }, function(error) {
        mqttClient.disconnect();
    });
});