0.0.4 • Published 6 years ago

aliyun-iot-mqtt v0.0.4

Weekly downloads
15
License
MIT
Repository
github
Last release
6 years ago

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

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago