如何在 React-Native 中实现 AWS IoT(设备)? [英] How to implement AWS IoT(device) in React-Native?
问题描述
我正在尝试使用 React-Native 实现 AWS-IoT(设备).
我已经使用了这些软件包,
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 步: 安装 nodeify 包 npm 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-down 包 npm 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,
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屋!