npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

aliyun-iot-mqtt

0.0.4 • Public • Published

aliyun-iot-mqtt

npm-version travis-ci coverage npm-download

Aliyun IoT Hub MQTT client for Node.js

Installation

You can install it as dependency with npm.

# save into package.json dependencies with -S 
$ npm install aliyun-iot-mqtt -S

Usage

Aliyun IoT Hub mqtt client with authrozied by productKey & deviceName & deviceSecret.

GET Data

const Mqtt = require('aliyun-iot-mqtt');
 
const client = Mqtt.getAliyunIotMqttClient({
    productKey: "",
    deviceName: "",
    deviceSecret: "",
    regionId: "cn-shanghai",
 
    keepalive:120 // mqtt options
});
 
 
client.on('connect', function() {
    console.log("connect")
})
 
client.end(function (){
    console.log("end")
})
 

TLS mqtts

aliyun_iot_root.cer

var trustedCA = fs.readFileSync(path.join(__dirname, '/aliyun_iot_root.cer'))
 
var options = {
    productKey: "",
    deviceName: "",
    deviceSecret: "",
    regionId: "cn-shanghai",
    protocol: 'mqtts',
    ca: trustedCA,
 
    keepalive:120 // mqtt options
};
 

Subscribe Topic

client.subscribe(topic)
 

Publish Message

client.publish(topic, 'Hello mqtt')
client.publish(topic, 'Hello mqtt', { qos: 1 })
 

Receive Message

client.on('message', function(topic, message) {
    console.log(topic+"," + message.toString())
})
 

Bugs

install

npm i aliyun-iot-mqtt

Downloadsweekly downloads

15

version

0.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability