IPWorks IoT 2020 Node.js Edition

Questions / Feedback?

CleanSession Property

Determines whether a clean session is used once connected.

Syntax

 mqttsn.getCleanSession([callback])
 mqttsn.setCleanSession( cleanSession, [callback])

Default Value

TRUE

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for the getCleanSession([callback]) method is defined as:

function(err, data){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'data' is the value returned by the method.

The callback for the setCleanSession([callback]) method is defined as:

function(err){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This property determines whether or not the class should instruct the server to use a clean session when it connects. (Note that this property must be set to the desired value before calling Connect.)

By default, CleanSession is true, so the server will discard any state data previously associated with the current ClientId once the class has connected successfully. In addition, the server will not save any state data when the class disconnects.

Setting CleanSession to False before connecting will cause the server to re-associate any previously stored state data for the current ClientId. The server will also save any state data that exists when the class is disconnected.

The server-side session state consists of:

  • client subscriptions,
  • QoS 1 and 2 messages which are buffering or unacknowledged,
  • QoS 2 messages received from the client but not completely acknowledged, and
  • the WillMessage and WillTopic if set.

Note that retained messages are not deleted as a result of a session ending, but are not part of the session state.

This property is not available at design time.

Data Type

Boolean

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Node.js Edition - Version 20.0 [Build 8265]