Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use aws-iot-device-sdk with react-native

I have tested aws-iot-device-sdk as shown on the image below. On my console I get topics from aws IoT. aws-iot-device-sdk

My question is when I try to integrate it into my react native application. below is my package.json for my react-native application enter image description here

When i reference the aws-iot-device-sdk and configure the setting in my react-native application I get error associated with the aws-iot-device-ssdk. Is this sdk compatible with react native? If so how do I configure the setting to push notification to my react native from an Aws IoT device?

like image 830
Sithelo Ngwenya Avatar asked Apr 21 '17 08:04

Sithelo Ngwenya


People also ask

What is AWS IoT SDK?

The AWS IoT C++ Device SDK allows developers to build connected applications using AWS and the AWS IoT APIs. Specifically, this SDK was designed for devices that are not resource constrained and require advanced features such as message queuing, multi-threading support, and the latest language features.

Which library is used to connect with Awsiot?

C-SDK is a collection of MIT licensed open source libraries that make it faster to securely connect embedded IoT devices to AWS IoT Core.

How do I get AWS IoT endpoint?

To learn your account's device data endpoint, you can find it in the Settings page of your AWS IoT Core console.


1 Answers

To use aws-iot-device-sdk in React-Native, you need to follow Viotti's suggestion above (https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-371159865) but with some new additions including adding 'url' and 'events' to the nodeify step. The problem we all face is that React-Native uses JavaScriptCore which is not the same as NodeJS and it is not the same as any specific browser JS engine either, though it is used in Safari. In order to use aws-sdk and aws-iot-device-sdk you need to include libraries that replace several important NodeJS libraries. rn-nodeify is an NPM package that makes this somewhat easy to do. The key step in the walk through on GitHub is here: npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process,events,url" --hack

This will install libraries that replace what is missing when not in nodejs, and create a shim.js file that you need to copy to your project's files and import. Within that Shim file you'll need to also make further modifications. buffer should already be installed, but the require or import statement must read `import { Buffer } from 'buffer/'; with the trailing slash, to separate it from the nodejs version for confused transpilers.

Other libraries I have needed for this include react-native-crypto, which can be used to replace NodeJS's crypto. Edit rn-nodeify's shim file to allow crypto. In order to make use of WSS on AWS in React-Native I've also used react-native-wss which helps handle certs in WSS.

like image 63
d36williams Avatar answered Sep 20 '22 13:09

d36williams