aliyun-iot-mqtt
v0.0.4
Published
阿里云IoT物联网套件客户端
Downloads
39
Maintainers
Readme
aliyun-iot-mqtt
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
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())
})