认证与连接

更新时间:2018-10-23 21:26:23

设备身份信息设置

在程序中需要指定对阿里云NodeJS Link Kit SDK的依赖,并输入设备的三元组信息:

var aliyunIot = require('aliyun-iot-device-sdk');

var device = aliyunIot.device({
  productKey: '<productKey>',
  deviceName: '<deviceName>',
  deviceSecret: '<deviceSecret>'
});

device.on('connect', () => {
  console.log('connect successfully!');
});

注:如果设备连接异常断开,程序会自动尝试与云端建立连接。

设置云端站点 region

通过 regionId 指定 region,例如指定为 cn-hangzhou :

var aliyunIot = require('aliyun-iot-device-sdk');

var device = aliyunIot.device({
  productKey: '<productKey>',
  deviceName: '<deviceName>',
  deviceSecret: '<deviceSecret>',
  regionId: 'cn-hangzhou'
});

device.on('connect', () => {
  console.log('connect successfully!');
});

results matching ""

    No results matching ""