无法通过本地离子应用程序连接到azure iot hub

问题描述 投票:0回答:1

我正在尝试将我的离子4应用程序(角度7)与azure iot hub连接。我正在尝试将msgs从我的应用程序发送到iot hub。在我的离子项目中下载了“azure-iothub”并尝试导入“client”以形成连接但是在构建错误时。

试图为浏览器设置这些特定模块为false,它会生成警告,但app不会加载到localhost上。还尝试了http post请求,但也出现了CORS错误,因为“localhost不允许访问”。


import { Platform } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {Client} from 'azure-iothub';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
    var connectionString = '**********';

    var client = Client.fromConnectionString(connectionString);

    client.open(function (err) {
      if (err) {
        console.error('Could not connect: ' + err.message);
      } else {
        console.log('Service client connected');
    }});

  }
}

得到以下错误 - error while building

angular azure ionic-framework azure-iot-hub
1个回答
0
投票

浏览器不支持使用Azure IoT Node SDK。

© www.soinside.com 2019 - 2024. All rights reserved.