npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kaaiot/mqtt-client

v1.0.0

Published

Comprehensive MQTT client tailored for the Kaa IoT platform, providing a range of methods to interact with the platform's features.

Downloads

4

Readme

KaaIoT Mqtt Client

Comprehensive MQTT client tailored for the Kaa IoT platform, providing a range of methods to interact with the platform's features. It encapsulates the complexity of MQTT communication, offering a user-friendly interface for IoT applications.

This client works in Node.js environment. Requires Node.js 16+. Based on MQTT.js library.

Installation

npm i @kaaiot/mqtt-client

Usage

Import createKaaMqttClient, provide connectionUrl, you device appVersionName and token.

import { createKaaMqttClient } from '@kaaiot/mqtt-client';

const client = createKaaMqttClient({ appVersionName: '1.0', token: 'your-token', connectionUrl: 'mqtt://mqtt.cloud.kaaiot.com:1883'  });

client.publishMetadata({ deviceModel: 20 })

Available methods

createKaaMqttClient(kaaOptions, mqttClientOptions: mqtt.Options)

mqttClientOptions are the options compatible with mqtt.Client constructor options

publishDataCollection(dataSamples: DataSample | DataSample[], callback?: StatusCallback<void>, errorCallback?: ErrorCallback, requestId?: string): void

Publishes single or multiple data samples.

client.publishDataCollection([{ temperature: 22.5 }], (status) => {
  console.log('Data published with status:', status);
});

publishPlainDataSample(metricName: string, dataSample: PlainDataSample, callback?: StatusCallback<void>, errorCallback?: ErrorCallback, requestId?: string): void

Publishes a plain data sample with a metric name.

client.publishPlainDataSample('temperature', '22.5');

getAllMetadataKeys(callback?: ResponseCallback<string[]>, errorCallback?: ErrorCallback, requestId?: string): void

Retrieves all metadata keys.

client.getAllMetadataKeys((keys) => {
  console.log('Metadata keys:', keys);
});

getMetadata(callback?: StatusCallback<Record<string, any>>, errorCallback?: ErrorCallback, requestId?: string): void

Retrieves all metadata values.

client.getMetadata((metadata) => {
  console.log('Metadata:', metadata);
});

publishMetadata(payload: MetadataPayload, callback?: StatusCallback, errorCallback?: ErrorCallback, requestId?: string): void

Publishes a full metadata update.

client.publishMetadata({ deviceId: '12345' });

publishMetadataKeys(metadata: MetadataPayload, callback?: StatusCallback, errorCallback?: ErrorCallback, requestId?: string): void

Partially updates metadata keys.

client.publishMetadataKeys({ deviceId: '12345' });

deleteMetadataKeys(keys: string[], callback?: StatusCallback, errorCallback?: ErrorCallback, requestId?: string): void

Deletes a list of metadata keys.

client.deleteMetadataKeys(['deviceId']);

getPendingCommands<T>(commandType: string, callback?: CommandsPendingCallback<T>, errorCallback?: ErrorCallback): void

Gets a list of pending commands.

client.getPendingCommands('reboot', (commands, topic, reportHandler) => {
  // Handle commands and report results
});

reportCommandExecutionResult<T>(commandType: string, results: CommandResult<T>[], errorCallback?: ErrorCallback, requestId?: string): void

Reports the results of command execution.

client.reportCommandExecutionResult('reboot', [{ id: 'cmd1', statusCode: 200, payload: 'OK' }]);

getConfigurationJson(payload: GetConfigurationPayload, callback?: ConfigurationPendingCallback, errorCallback?: ErrorCallback, requestId?: string): void

Retrieves the configuration in JSON format.

client.getConfigurationJson({}, (config) => {
  console.log('Configuration:', config);
});

reportAppliedConfiguration(payload: AppliedConfigurationPayload, callback?: ResponseCallback, errorCallback?: ErrorCallback, requestId?: string): void

Reports the applied configuration.

client.reportAppliedConfiguration({ configId: 'cfg123', statusCode: 200 });

reportCurrentSoftwareVersion(payload: ReportSoftwareRequestPayload, callback?: ResponseCallback, errorCallback?: ErrorCallback): void

Reports the current software version.

client.reportCurrentSoftwareVersion({ configId: 'sw123' });

getSoftwareUpdate(callback?: ResponseCallback<SoftwareResponse>, errorCallback?: ErrorCallback, requestId?: string): void

Retrieves the software update information.

client.getSoftwareUpdate((softwareInfo) => {
  console.log('Software update info:', softwareInfo);
});

disconnect(callback?: mqtt.DoneCallback): void

Safely unsubscribe from all subscriptions and clear the subscriptions record. This method should be called before shutting down the application to ensure a clean disconnect.

client.disconnect(() => {
  console.log('Client destroyed and all subscriptions are cleared');
});

connect(): void

Establishes a connection to the MQTT broker. This method should be called if the manualConnect option is set to true in the client options.

// When manualConnect is true, you need to pass it in the mqttClientOptions and call connect manually
const client = createKaaMqttClient(
  { appVersionName: '1.0', token: 'your-token', connectionUrl: 'mqtt://mqtt.cloud.kaaiot.com:1883' },
  { manualConnect: true }
);

// Connect to the MQTT broker
client.connect();