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

Package Sidebar

Install

npm i aliyun-iot-mqtt

Weekly Downloads

12

Version

0.0.4

License

MIT

Last publish

Collaborators

  • wongxming