UNPKG

node-red-contrib-mobius-flow-thingsboard

Version:

Node-RED nodes to work with MOBiUSFlow and ThingsBoard.io

71 lines (70 loc) 2.87 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; export interface IThingsboardMqttClient { on(type: 'connecting', callback: () => void): any; on(type: 'disconnected', callback: () => void): any; on(type: 'connected', callback: () => void): any; on(type: 'attributes', callback: (topic: any, payload: any) => void): any; closeMqttConnection(): any; /** * Register a device with Thingsboard as connected * @param deviceName The device name */ registerDeviceAsConnected(deviceName: string): void; /** * Register a device with Thingsboard as disconnected * @param deviceName The device name */ registerDeviceAsDisconnected(deviceName: string): void; /** * Update device client attributes on Thingsboard * @param deviceName The device name * @param attributes Attributes as an object of key value pairs * Resolves if attributes are updated, else rejects */ updateDeviceClientAttributes(deviceName: string, attributes: any): Promise<any>; /** * Update device telemetry on Thingsboard * @param deviceName The device name * @param telemetry Telemetry as an object of key value pairs * Resolves if telemetry is updated, else rejects */ updateDeviceTelemetry(deviceName: string, timestamp: number, telemetry: any): Promise<any>; } export declare class ThingsboardMqttClient extends EventEmitter implements IThingsboardMqttClient { private siteURL; private gatewayId; private accessToken; private allowSelfCert; private mqttClient; private slowReconnectCounter; private reconnectTimeout; constructor(siteURL: string, gatewayId: string, accessToken: string, allowSelfCert: boolean); closeMqttConnection(): Promise<void>; updateDeviceClientAttributes(deviceName: string, attributes: any): Promise<any>; updateDeviceTelemetry(deviceName: string, timestamp: number, telemetry: any): Promise<any>; registerDeviceAsConnected(deviceName: string): void; registerDeviceAsDisconnected(deviceName: string): void; /** * Get the state of the MQTT connection * @returns true if connected to the Thingsboard instance, else false */ private isConnected; /** * Connect to the Thingsboard instance * @returns A Promise which resolves if a connection is established, or rejects with the error if a connection fails */ private connect; /** * Disconnect from the Thingsboard instance * @returns A Promise which resolves when the connection has ended */ private disconnect; /** * Publish a device event to the Thingsboard instance * @param {string} topic - The event topic * @param {string} payload - The event payload * @param {mqtt.QoS} qos - The QoS to use when publishing */ private publish; }