目標:使用節點模塊azure-iot-hub從瀏覽器(角度2)創建天藍色iot集線器設備。我可以從瀏覽器創建IoT Hub設備嗎?
問題:蔚IOT常見取決於封裝,加密,不會在瀏覽器中運行。
步驟重新創建:
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);
}
}
從Google 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 - 這表明切換加密到webcrypto
潛在的解決方案:開關加密到webcrypto - 將需要重寫蔚IOT-common/lib目錄/ authorization.js
問題:
- 有任何人使用節點模塊從瀏覽器創建集線器設備azure-iot-hub?
- 有沒有人使用替代方法從瀏覽器創建集線器設備?
- 如果不是Q1.2 - 我的潛在解決方案是否可行?
您現在可以在Azure門戶中爲IoT Hub創建設備。轉到Azure IoT Hub儀表板,然後打開Device Explorer菜單。 – Sneezry