1.0.0 • Published 4 years ago
enos-mqtt-sdk-nodejs v1.0.0
Using EnOS Device SDK for MQTT
Table of Contents
Prerequisites
Installing Node
To use the EnOS Device SDK for NodeJS, you will need to install Node.js 8 or later.
Obtaining the SDK
npm is a command-line package manager that is installed with Node.js is installed, and will be used to obtain the SDK.
$ npm install --save enos-mqtt-sdk-nodejs
Feature List
For the list of features supported by this SDK and the availability of EnOS device connectivity and management features in all SDKs we provide, see EnOS Device SDK.
Quick Start
- Establishing connection with EnOS Cloud
const {DeviceClient, SECURE_MODE} = require('enos-mqtt-sdk-nodejs');
// create client instance
const clientOptions = {
brokerUrl: 'brokerUrl',
secureMode: SECURE_MODE.VIA_DEVICE_SECRET,
productKey: 'productKey', deviceKey: 'deviceKey', deviceSecret: 'deviceSecret'
}
const client = new DeviceClient(clientOptions);
// listen to 'connect' event
client.on('connect', () => {
console.log('connected');
})
// listen to 'close' event
client.on('close', () => {
console.log('connection closed');
})
// establish connection
client.connect().then(async() => {
// interact with the cloud
});
- Reporting measurement points
const mpResponse = await client.deviceData.postMeasurepoint({
point: {
measurepoints: {
mp_age: 20
}
}
});
console.log(mpResponse.data);
- Closing the connection
client.close();
Sample Code
- Establishing Connection with EnOS Cloud
- Device Tags
- Device Attributes
- Reporting Measurement Points
- Reporting Events
- Receiving Commands from Cloud
- Passing Through Device Information or Receving Passed-through Information from Cloud
- Managing Sub-devices
Related Information
- To learn more about EnOS IoT Hub, see EnOS IoT Hub Documentation.
API Reference
See api reference
Release Notes
- 2020/01/15 (Initial Release)