如何在 React-Native 中实现 AWS IoT(设备)? [英] How to implement AWS IoT(device) in React-Native?

查看:42
本文介绍了如何在 React-Native 中实现 AWS IoT(设备)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 React-Native 实现 AWS-IoT(设备).

我已经使用了这些软件包,

1) aws-iot-device-sdk-js

2) react-native-aws-iot-device-shadows

并且在使用该软件包时出现了很多错误.我可以调试一些,但没有得到预期的结果.

我正在为聊天应用程序实施 AWS-IoT.

我使用 REST API 成功创建了一个 IoT 会话,并将它们作为响应iotEndpoint、region、accessKey、secretKey、sessionToken.但是使用这些凭据,我无法使用上述软件包连接.

解决方案

我想通了,

第一步:安装aws-iot npm包npm install --save aws-sdk aws-iot-device-sdk

第 2 步: 安装 nodeifynpm install --save-dev rn-nodeify

第 3 步: 运行此命令安装指定的一系列软件包

npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process" --hack

请等待所有软件包安装完毕"

第 4 步: 转到 package.json -> 在 scripts 部分添加,

"postinstall": "rn-nodeify --install fs,util,path,tls,stream,buffer,global,process --hack"

第 5 步:安装 asyncstorage-downnpm install --save asyncstorage-down

第 6 步:rn-nodeify 将在您的 react-native 项目的根部分自动生成一个文件 shim.js.只需将它导入 index.js 文件中,就像这样 import './shim'

最后,您可以使用 aws-iot 包了!!!

建议在后端使用 REST API 生成上述问题中指定的物联网会话密钥.

I am trying to Implement AWS-IoT(device) using React-Native.

I have used the packages,

1) aws-iot-device-sdk-js

2) react-native-aws-iot-device-shadows

and got a lot of errors while using the package. I could debug few, but did not get expected results.

I am Implementing AWS-IoT for Chatting application.

I am successfully creating an IoT session using REST APIs and get these as responses iotEndpoint, region, accessKey, secretKey, sessionToken. But using these credentials I am unable to Connect using the above packages.

解决方案

I figured this out,

Step 1: Install aws-iot npm package npm install --save aws-sdk aws-iot-device-sdk

Step 2: Install the nodeify package npm install --save-dev rn-nodeify

Step 3: Run this command to install series of packages specified

npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process" --hack

"Please wait until the all the packages are installed"

Step 4: Goto package.json -> in scripts section add,

"postinstall": "rn-nodeify --install fs,util,path,tls,stream,buffer,global,process --hack"

Step 5 : Install the asyncstorage-down package npm install --save asyncstorage-down

Step 6: rn-nodeify will auto-generate a file shim.js in the root part of your react-native project. Just import it in index.js file like this import './shim'

Finally, you are ready to use your aws-iot package !!!

It is advisable to generate the iot-session keys as specified in the question above using REST API's in the backend.

这篇关于如何在 React-Native 中实现 AWS IoT(设备)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆