-1

使用 NodeJS,我正在使用此处的基本示例文档: https ://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted

但是我收到此错误:

iothub.Device 不是 Object 的构造函数。(/Users/luis.valencia/Projects/IoTSamples/NodeJSIoTHelloWorld /CreateDeviceIdentity.js:7:14) 在 Module._compile (module.js:541:32) 在 Object.Module._extensions..js (module.js:550 :10) 在 Module.load (module.js:458:32) 在 tryModuleLoad (module.js:417:12) 在 Function.Module._load (module.js:409:3) 在 Module.runMain (module.js :575:10) 在运行时 (bootstrap_node.js:352:7) 在启动时 (bootstrap_node.js:144:9) 在 bootstrap_node.js:467:3

我的代码如下:

'use strict';
var iothub = require('azure-iothub');
var connectionString = 'HostName=xyz.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xyz=';
var registry = iothub.Registry.fromConnectionString(connectionString);
var deviceId = "helloworlddevice";

var device = new iothub.Device(null);
device.deviceId = deviceId;

registry.create(device, function(err, deviceInfo, res) {
  if (err)
    registry.get(device.deviceId, printDeviceInfo); 

  if (deviceInfo)
    printDeviceInfo(err, deviceInfo, res) 
});

function printDeviceInfo(err, deviceInfo, res) {
  if (deviceInfo)
    console.log('Generated device key: ' + deviceInfo.authentication.SymmetricKey.primaryKey);
}
4

1 回答 1

0

npm包有一个bug,在github上报告给MS后,修复了,一夜之间发布,所以我又重新安装了包,问题解决了。

于 2016-11-17T19:53:05.717 回答