【发布时间】:2019-03-25 23:06:11
【问题描述】:
我正在尝试将我的 ionic 4 应用程序(角度 7)与 azure iot hub 连接。我正在尝试将消息从我的应用程序发送到 iot 集线器。在我的 ionic 项目中下载“azure-iothub”并尝试导入“客户端”以形成连接,但在构建时出现错误。
尝试将这些特定模块设置为 false 浏览器,它构建时会发出警告,但应用程序不会在 localhost 上加载。 还尝试了http post请求,但也出现了CORS错误,因为“localhost is not allowed to access”。
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
【问题讨论】:
-
我可以使用 azure iot hub 连接到我的 ionic 应用程序的任何其他方式????????
标签: angular azure ionic-framework azure-iot-hub