Skip to main content

mqttclient.disconnect(callback)

Close an open connection to an MQTT broker

Availability

Agent

Parameters

Name Type Description
callback Function Optional function called upon disconnection

Returns

Nothing

Description

This method closes the mqttclient’s connection to its specified MQTT broker.

Optionally, you may provide a function which will be called when the connection has been closed. The callback function should have no parameters of its own.

You should always wait until the callback has fired before you make any attempt to reconnect. This ensures that the disconnection process, which is highly asynchronous, has fully completed. Attempting to connect when the client has not fully disconnected will throw an exception.