Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

huaweicloud-iot-device-sdk

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

huaweicloud-iot-device-sdk

华为云IoT物联网平台户端

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
1
-80%
Maintainers
1
Weekly downloads
 
Created
Source

huaweicloud-iot-device-sdk

npm-version npm-download

Huawei IoT SDK MQTT client for Node.js

Installation

You can install it as dependency with npm.

$ # save into package.json dependencies with -S
$ npm install huaweicloud-iot-device-sdk -S

Usage

Huawei IoT mqtt client with authrozied by deviceId & deviceSecret.

GET Data

const path = require('path');
const huaweiIoT = require('huaweicloud-iot-device-sdk');

const options = {
    deviceId: "your deviceId",
    deviceSecret: "your deviceSecret",
    caFilePath: path.join(__dirname, 'hw-iot-root.pem'),
    host:'your iot host'
}


//建立连接
var client = huaweiIoT.getHuaweiIoTClient(options);
client.on('message', function(topic, message) {
    console.log("topic " + topic)
    console.log("message " + message)

})
client.subscribe(`/huawei/v1/devices/${options.deviceId}/command/json`)

var topic = `/huawei/v1/devices/${options.deviceId}/data/json`
var postJson = {
    msgType: "deviceReq",
    data: [
        {
            serviceId: "pop",
            serviceData: {
                stackId:4
            }
        }
    ]
}
client.publish(topic, JSON.stringify(postJson))

client.end(function (){
    console.log("end")
})

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

Keywords

huawei

FAQs

Package last updated on 09 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts