RetryMQTT.lastError

Overview

Contains the last error encountered while trying to maintain the MQTT connection. Note that any error messages will have already been logged.

Added in version 2.1.20

Format

var retryMqtt = new RetryMQTT(options);

//...

var lastError = retryMqtt.lastError;

Value Description Type Required
lastError The last error encountered while trying to maintain the MQTT connection. Will be "connecting" if trying to connect for the first time or "connected" if successfully connected. MQTTClient object Return

Example

Copy
/* Publishes all scans to a topic named "scan", but only if currently connected to MQTT server.
 * If unable to send message, shows the last error message in a toast to the user.
 */

retryMqtt = new RetryMQTT({
    broker: "mqtts://mysecuremqtt.example.com"
});

WLEvent.on("Scan", function(event) {
    if (retryMqtt.lastError === "connected") {
        retryMqtt.publish("scan", event.data);
    } else {
        View.toast(retryMqtt.lastError, false);
    }
});