【发布时间】:2017-04-18 00:03:50
【问题描述】:
目标:使用节点模块 azure-iot-hub 从浏览器 (angular2) 创建一个 azure iot hub 设备。
问题: azure-iot-common 依赖于一个包 crypto ,它在浏览器中不起作用。
重建步骤:
import { Component, OnInit } from '@angular/core';
let iothub = require(‘azure-iothub’);
const connectionString = ‘HostName=<my-host>.azure-devices.net;SharedAccessKeyName=<my-key-name>;SharedAccessKey=<my-key>=’;
@Component({
selector: 'acn-shop',
template: `
<div class="al-main">
<div class="al-content container-fluid">
<h1>Azure IoT Hub Devices</h1>
</div>
</div>`
})
export class ShopComponent implements OnInit {
constructor() {
}
public ngOnInit() {
this.connect();
}
public connect() {
console.log('Calling connect()');
const registry = iothub.Registry.fromConnectionString(connectionString);
}
}
从 Chrome 工具控制台
Error: Uncaught (in promise): TypeError: crypto.createHmac is not a function
TypeError: crypto.createHmac is not a function
at Object.hmacHash (authorization.js:36)
at Function.create (shared_access_signature.js:67)
at Object.create (shared_access_signature.js:15)
at Function.fromConnectionString (registry.js:65)
at ShopComponent.Array.concat.ShopComponent.connect (shop.component.ts:32)
… (goes on for a bit) ...
- github 上有一个类似的问题 - https://github.com/ipfs/js-ipfs/issues/270 - 建议将 crypto 切换到 webcrypto
潜在解决方案: 将 crypto 切换为 webcrypto - 需要重写 azure-iot-common/lib/authorization.js
问题:
- 是否有人使用节点模块 azure-iot-hub 从浏览器创建集线器设备?
- 是否有人使用其他方法从浏览器创建集线器设备?
- 如果对 Q1,2 否决 - 我的潜在解决方案是否可行?
【问题讨论】:
-
您现在可以在 Azure 门户中为 IoT 中心创建设备。转到 Azure IoT Hub 仪表板,然后打开设备资源管理器菜单。
标签: azure-iot-hub azure-iot-sdk