Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wongxming/huaweicloud-iot-device-sdk
华为云 IoT nodejs SDK
https://github.com/wongxming/huaweicloud-iot-device-sdk
huawei iot nodejs
Last synced: 3 days ago
JSON representation
华为云 IoT nodejs SDK
- Host: GitHub
- URL: https://github.com/wongxming/huaweicloud-iot-device-sdk
- Owner: wongxming
- License: mit
- Created: 2019-12-10T05:17:06.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T05:52:15.000Z (about 2 years ago)
- Last Synced: 2024-10-04T15:48:41.459Z (about 1 month ago)
- Topics: huawei, iot, nodejs
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## huaweicloud-iot-device-sdk
[![npm-version](https://img.shields.io/npm/v/huaweicloud-iot-device-sdk.svg)](https://npmjs.org/package/huaweicloud-iot-device-sdk)
[![npm-download](https://img.shields.io/npm/dm/huaweicloud-iot-device-sdk.svg)](https://npmjs.org/package/huaweicloud-iot-device-sdk)[Huawei IoT SDK](https://www.aliyun.com/product/iot) MQTT client for Node.js
## Installation
You can install it as dependency with npm.
```sh
$ # 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
```js
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
```js
client.subscribe(topic)```
### Publish Message```js
client.publish(topic, 'Hello mqtt')
client.publish(topic, 'Hello mqtt', { qos: 1 })```
### Receive Message
```js
client.on('message', function(topic, message) {
console.log(topic+"," + message.toString())
})```