node-red-contrib-mobius-flow-thingsboard
Version:
Node-RED nodes to work with MOBiUSFlow and ThingsBoard.io
47 lines (46 loc) • 1.61 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import * as mqtt from 'mqtt';
export interface IMQTTConfig {
site: string;
gatewayId: string;
isLocal: boolean;
accessToken: string;
keepAlive: number;
reconnectPeriod: number;
slowReconnectPeriod: number;
}
export declare class IThingsboardMQTTGateway extends EventEmitter {
private config;
private mqttClient;
private slowReconnectCounter;
private reconnectTimeout;
constructor(config: IMQTTConfig);
/**
* Get the state of the MQTT connection
* @returns true if connected to the Thingsboard instance, else false
*/
isConnected(): boolean;
/**
* Connect to the Thingsboard instance
* @returns A Promise which resolves if a connection is established, or rejects with the error if a connection fails
*/
connect(): Promise<unknown>;
/**
* Disconnect from the Thingsboard instance
* @param {boolean} [force = false] - Set true to force an immediate disconnects or false to wait for all
* pending messages to complete before disconnecting
* @returns A Promise which resolves when the connection has ended
*/
disconnect(force?: boolean): Promise<unknown>;
/**
* Publish a device event to the Thingsboard instance
* @param {string} payload - The event payload
* @param {mqtt.QoS} qos - The QoS to use when publishing
*/
publish(topic: string, payload: string, qos: mqtt.QoS): Promise<any>;
/**
* Force a reconnect if the connection is down for too long
*/
private _reconnect;
}