Closed stephenkeep closed 4 years ago
Hello @stephenkeep,
Thank you for your request. We have seen interest in React Native from other customers and have added this to our SDK backlog.
John, AWS IoT
Hi @stephenkeep, We noticed you have posted a request for React Native on the AWS Node JS SDK as well. It seems you were unable to use any AWS services because of the lack of integration. I was wondering if you could provide us with some information on how you are planning to use the SDK with React Native? If you have attempted to integrate the IoT device SDK for Node JS and found issues, please let us know where you were blocked as well.
This information would be very useful in helping us re-prioritize this request. Thank you for reaching out again and helping us better understand our customers' needs. We apologize for any problems this has caused you. Please do let us know if we can help in any other way as well.
Rahul
Any update on this? We are looking at using IoT to pass messages between devices and services if this is simple.
I have an actual code for react native, is not that hard, my only issue at the momment is that i have the iot device name hard coded.
2017-03-20 14:52 GMT-03:00 rthameem notifications@github.com:
+1 Any update on this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-287843072, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOyDB5BZmSBjVFC5-dXmmR0NVEtWF8vks5rnrzwgaJpZM4Jqqj5 .
@yayolius Do you have an example ?
I will try to add something between today and tomorrow.
2017-03-21 22:58 GMT-03:00 Andrew McClenaghan notifications@github.com:
@yayolius https://github.com/yayolius Do you have an example ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-288275391, or mute the thread https://github.com/notifications/unsubscribe-auth/ACOyDMOl-zEIPmvLVJglO02FTZJ4DOd4ks5roIBFgaJpZM4Jqqj5 .
Hi, we're also looking to use IOT on React Native but are getting serious errors. Some docs would be extremely helpful.
@garrett-gottlieb @yayolius any luck with it?
@MattyK14 we moved to MQTT.js with VerneMQ and are very satisfied. IOT is nowhere near production-ready.
Any update on this?
@MattyK14 Did you find any sample with aws iot react native paho mqtt ?
+1 would be really nice to have an example how to integrate it with react native
@SanyasiraoM are you using Cognito authentication?
Here's a snippet I've trimmed down. I used Cognito to authenticate, which signs the IoT URL. I hope I didn't cut too much & that it's useful to you.
@MattyK14 Thanks a lot for the snippet. After some tweaks it did work for me.
@ambientlight @MattyK14 Any work around for make the socket connection alive when app is in the closed state[Android react native app].
<AWSIoTMQTT
type="shadow"
ref={(ref) => { this.AWSIoTMQTT = ref; }}
region={config.AWS_REGION}
host={config.MQTT_HOST}
onConnect={() => this.onConnect()}
onDelta={(thingId, stateObject) => this.onDelta(thingId, stateObject)}
onStatus={(thingId, statusType, clientToken, stateObject) =>
this.onStatus(thingId, statusType, clientToken, stateObject)}
onThingConnected={(thingId) => { this.onThingConnected(thingId); }}
/>
@SanyasiraoM I'm working in the same issue, maybe a ping-pong pattern ?
@MattyK14 Can we use your snippet in ReactJS app also? I am getting following error:
./node_modules/react-native-paho-mqtt/src/Client.js
Module parse failed: Unexpected token (27:5)
You may need an appropriate loader to handle this file type.
| // ------------------------------------------------------------------------
|
| type ConstructorOptions = {
| uri: string,
| clientId: string,
I would also like to see instructions for React Native has there been any movement on this?
Check my repo: https://www.npmjs.com/package/react-native-aws-iot-device-shadows I have added support for redux iot shadows
On Fri, Feb 16, 2018 at 2:13 PM, enscripter notifications@github.com wrote:
I would also like to see instructions for React Native has there been any movement on this?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-366345833, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvnu-Sw-sndVpMKJXcjyOmAvD_nJA4Nks5tVeFjgaJpZM4Jqqj5 .
--
James Jara jamesjara.com http://jamesjara.com Software Developer M: +(506) 87944598 Computer Society Network Founder Costa Rica Security team leader Inventor of x7cloud framework pgp MIT key https://pgp.mit.edu/pks/lookup?search=jamesjara%40gmail.com&op=index [image: innosystem][image: computer society][image: x7cloud framework]
_.-~-.
7'' Q..\
_7 (_
_7 _/ _q. /
_7 . ___ /VVvv-'_ .
7/ / /~- _\ '-. .-' / // ./ ( /-~-/||'=. '::. '-~'' { / // ./{ V V-~-~| || '' ':::. ''~-~..-'' / // / { / { / VV/-~-~-|/ \ .'_'. '. ':: ''.
| | | || | / \ | | | || /| \ / || | | ' \ | || |_ \ \/ /| | | || '_| | | | | | \ ) || | / / | | | || | > < | || || | | || | ) |/ / | | / / || || || //_\ _/ |_| _/ |__/|____||| /_/
Awesome I have tried this, but I only need to publish to a AWS Iot topic from react. Maybe I am looking in the wrong place I can use the cURL as suggested on the AWS docs:
curl --tlsv1.2 --cacert root-CA.crt --cert 4b7828d2e5-certificate.pem.crt --key 4b7828d2e5-private.pem.key -X POST -d "{ \"serialNumber\": \"G030JF053216F1BS\", \"clickType\": \"SINGLE\", \"batteryVoltage\": \"2000mV\" }" "https://a1pn10j0v8htvw.iot.us-east-1.amazonaws.com:8443/topics/iotbutton/virtualButton?qos=1"
But I don't know how to pass the certs/keys through react or if I can accomplish the same through another library.
Certs are commonly used for thing device itself, for mobile or web use the WSS protocol, with the STS credentials
On Fri, Feb 16, 2018 at 3:36 PM, enscripter notifications@github.com wrote:
Awesome I have tried this, but I only need to publish to a AWS Iot topic from react. Maybe I am looking in the wrong place I can use the cURL as suggested on the AWS docs:
curl --tlsv1.2 --cacert root-CA.crt --cert 4b7828d2e5-certificate.pem.crt --key 4b7828d2e5-private.pem.key -X POST -d "{ "serialNumber": "G030JF053216F1BS", "clickType": "SINGLE", "batteryVoltage": "2000mV" }" " https://a1pn10j0v8htvw.iot.us-east-1.amazonaws.com:8443/topics/iotbutton/ virtualButton?qos=1"
But I don't know how to pass the certs/keys through react or if I can accomplish the same through another library.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-366365069, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvnu231TjHgIOxo5eh8d-jVQUc7SyhYks5tVfTEgaJpZM4Jqqj5 .
--
James Jara jamesjara.com http://jamesjara.com Software Developer M: +(506) 87944598 Computer Society Network Founder Costa Rica Security team leader Inventor of x7cloud framework pgp MIT key https://pgp.mit.edu/pks/lookup?search=jamesjara%40gmail.com&op=index [image: innosystem][image: computer society][image: x7cloud framework]
_.-~-.
7'' Q..\
_7 (_
_7 _/ _q. /
_7 . ___ /VVvv-'_ .
7/ / /~- _\ '-. .-' / // ./ ( /-~-/||'=. '::. '-~'' { / // ./{ V V-~-~| || '' ':::. ''~-~..-'' / // / { / { / VV/-~-~-|/ \ .'_'. '. ':: ''.
| | | || | / \ | | | || /| \ / || | | ' \ | || |_ \ \/ /| | | || '_| | | | | | \ ) || | / / | | | || | > < | || || | | || | ) |/ / | | / / || || || //_\ _/ |_| _/ |__/|____||| /_/
Is that in your library? Would you happen to have a sample of publishing to a topic? I can't seem to find anything close to what I need to do
I was able to make a RN 0.53 app communicate with the MQTT broker on AWS via WSS with the following steps.
First, install the AWS SDK JS and the AWS IoT Device SDK.
npm install --save aws-sdk aws-iot-device-sdk
Then, install RN Nodeify.
npm install --save-dev rn-nodeify
Use RN Nodeify to install eight Node libraries: fs, util, path, tls, stream, buffer, global, and process.
npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process" --hack
Put this command in the postinstall section of package.json
.
Also install asyncstorage-down.
npm install --save asyncstorage-down
Finally, edit index.js
and import the shim.js
file generated by RN Nodeify on its install command.
import './shim'
Ideally, the import './shim'
is the first instruction of index.js
.
Now, given your AWS region, IoT endpoint and Cognito identity pool, the following code should work.
import Aws from 'aws-sdk/dist/aws-sdk-react-native'
import AwsIot from 'aws-iot-device-sdk'
AWS_REGION = 'us-east-1' // Change if needed.
AWS_COGNITO_IDENTITY_POOL = 'us-east-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' // Fill in.
AWS_IOT_ENDPOINT = 'XXXXXXXXXXXXX.iot.us-east-1.amazonaws.com' // Fill in.
Aws.config.region = AWS_REGION
Aws.config.credentials = new Aws.CognitoIdentityCredentials({
IdentityPoolId: AWS_COGNITO_IDENTITY_POOL
})
Aws.config.credentials.get(() => {
const config = {}
let client
config.host = AWS_IOT_ENDPOINT
config.protocol = 'wss'
config.clientId = `client-${Math.floor((Math.random() * 100000) + 1)}`
config.accessKeyId = Aws.config.credentials.accessKeyId
config.secretKey = Aws.config.credentials.secretAccessKey
config.sessionToken = Aws.config.credentials.sessionToken
client = AwsIot.device(config)
client.on('connect', () => {
client.subscribe('some_topic')
})
client.on('message', (topic, message) => {
console.log(topic, message)
})
client.on('error', error => {
console.log(error)
})
})
This will work if your Cognito Identity Pool is configured to allow access to unauthenticated users, as explained in this tutorial. Otherwise you'll need extra code to attach user policies etc.
References:
Any update on React-Native integration with aws IoT. Does anybody has working example to subscribe/publish to the aws broker? Plain mqtt not to shadows.
Thanks
I'd like to add to @viotti's solution that you also need to add url
and events
as part of the npx rn-nodeify --install
script.
@rclai @richardlevano What about https://aws.github.io/aws-amplify/media/pub_sub_guide#aws-iot?
What? So if Amplify exists, what does it make of this SDK?
@rclai I also don't know exactly
use my repo https://github.com/jamesjara/react-native-aws-iot-device-shadows
Access directly to the mqtt rather than the shadow
On Mon, May 14, 2018 at 10:10 PM, SanyasiraoM notifications@github.com wrote:
@rclai https://github.com/rclai I also don't know exactly
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-389036859, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvnu97fTVK2iFaoVtxEmQ_GcJh6EpyVks5tylUlgaJpZM4Jqqj5 .
--
James Jara jamesjara.com http://jamesjara.com Software Developer M: +(506) 87944598 Computer Society Network Founder Costa Rica Security team leader Inventor of x7cloud framework pgp MIT key https://pgp.mit.edu/pks/lookup?search=jamesjara%40gmail.com&op=index [image: innosystem][image: computer society][image: x7cloud framework]
_.-~-.
7'' Q..\
_7 (_
_7 _/ _q. /
_7 . ___ /VVvv-'_ .
7/ / /~- _\ '-. .-' / // ./ ( /-~-/||'=. '::. '-~'' { / // ./{ V V-~-~| || '' ':::. ''~-~..-'' / // / { / { / VV/-~-~-|/ \ .'_'. '. ':: ''.
| | | || | / \ | | | || /| \ / || | | ' \ | || |_ \ \/ /| | | || '_| | | | | | \ ) || | / / | | | || | > < | || || | | || | ) |/ / | | / / || || || //_\ _/ |_| _/ |__/|____||| /_/
I was able to make a RN 0.53 app communicate with the MQTT broker on AWS via WSS with the following steps.
First, install the AWS SDK JS and the AWS IoT Device SDK.
npm install --save aws-sdk aws-iot-device-sdk
Then, install RN Nodeify.
npm install --save-dev rn-nodeify
Use RN Nodeify to install eight Node libraries: fs, util, path, tls, stream, buffer, global, and process.
npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process" --hack
Put this command in the postinstall section of
package.json
.Also install asyncstorage-down.
npm install --save asyncstorage-down
Finally, edit
index.js
and import theshim.js
file generated by RN Nodeify on its install command.import './shim'
Ideally, the
import './shim'
is the first instruction ofindex.js
.Now, given your AWS region, IoT endpoint and Cognito identity pool, the following code should work.
import Aws from 'aws-sdk/dist/aws-sdk-react-native' import AwsIot from 'aws-iot-device-sdk' AWS_REGION = 'us-east-1' // Change if needed. AWS_COGNITO_IDENTITY_POOL = 'us-east-1:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' // Fill in. AWS_IOT_ENDPOINT = 'XXXXXXXXXXXXX.iot.us-east-1.amazonaws.com' // Fill in. Aws.config.region = AWS_REGION Aws.config.credentials = new Aws.CognitoIdentityCredentials({ IdentityPoolId: AWS_COGNITO_IDENTITY_POOL }) Aws.config.credentials.get(() => { const config = {} let client config.host = AWS_IOT_ENDPOINT config.protocol = 'wss' config.clientId = `client-${Math.floor((Math.random() * 100000) + 1)}` config.accessKeyId = Aws.config.credentials.accessKeyId config.secretKey = Aws.config.credentials.secretAccessKey config.sessionToken = Aws.config.credentials.sessionToken client = AwsIot.device(config) client.on('connect', () => { client.subscribe('some_topic') }) client.on('message', (topic, message) => { console.log(topic, message) }) client.on('error', error => { console.log(error) }) })
This will work if your Cognito Identity Pool is configured to allow access to unauthenticated users, as explained in this tutorial. Otherwise you'll need extra code to attach user policies etc.
References:
@viotti I hope this solution can work, i have setup the dependencies and when i try to include shim in my index.js i get error Unable to resolve module
processfrom
shim.js`` . Here is below my installed dependencies. I am new to RN can you please check what is possibly wrong.
`"dependencies": {
"@react-native-community/async-storage": "^1.6.2",
"asyncstorage-down": "^4.2.0",
"aws-iot-device-sdk": "^2.2.1",
"aws-sdk": "^2.570.0",
"axios": "^0.19.0",
"native-base": "^2.13.8",
"path-browserify": "0.0.0",
"process": "^0.11.0",
"react": "16.9.0",
"react-native": "0.61.2",
"react-native-default-preference": "^1.4.1",
"react-native-gesture-handler": "^1.5.0",
"react-native-level-fs": "^3.0.0",
"react-native-maps": "^0.25.0",
"react-native-material-textfield": "^0.14.1",
"react-native-reanimated": "^1.4.0",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^1.10.3",
"readable-stream": "1.0.33",
"request": "^2.88.0",
"request-promise": "^4.2.5",
"stream-browserify": "^1.0.0",
"util": "~0.10.3"
}`
Regards,Ali
@alitele @jmklix It doesn't work with tls auth
Importing shim.js into index.js did not work for my React Native project. But after I added it to App.js, it worked.
we are now at 2021, is there a simple instruction to implement aws iot mqtt in in react native?
i am having this error after following: https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-553798572
`Event { "isTrusted": false, "message": "Code 1005 is reserved and may not be used.", }
Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info. (Saw setInterval with duration 128000ms)
hi guys any updates?
hi any updates on this ?
Hi, these are the steps how I successfully run this library. I am using react v17.0.2 and react-native v0.67.2.
npm install --save aws-sdk aws-iot-device-sdk
At that point it installed me aws-iot-device-sdk v2.2.11 and aws-sdk v2.1099.0npm install --save-dev rn-nodeify
npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process,events,url" --hack
"postinstall": "npx rn-nodeify --install 'fs,util,path,tls,stream,buffer,global,process,events,url' --hack"
npm install --save asyncstorage-down
import './shim';
And that's it.
@borisjwork I've followed all the steps, but still i'm getting below error.
TypeError: _$$_REQUIRE(dependencyMap[2], "fs").existsSync is not a function. (In '$$_REQUIRE(dependencyMap[2], "fs").existsSync(options.caCert)', '$$_REQUIRE(_dependencyMap[2], "fs").existsSync' is undefined)
@avinashsahoo Interesting, I didn't have that error, maybe it is due to the version of some library. Here is my package.json for a working example, it might be helpful. { "name": "awstest", "version": "1.0.0", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint .", "postinstall": "npx rn-nodeify --install 'fs,util,path,tls,stream,buffer,global,process,events,url' --hack" }, "dependencies": { "asyncstorage-down": "4.2.0", "aws-iot-device-sdk": "2.2.11", "aws-sdk": "2.1103.0", "buffer": "4.9.2", "path-browserify": "0.0.0", "process": "0.11.10", "react": "17.0.2", "react-native": "0.67.2", "react-native-fs": "2.19.0", "react-native-level-fs": "3.0.1", "readable-stream": "1.0.33", "stream-browserify": "1.0.0", "util": "0.10.4" }, "devDependencies": { "@babel/core": "7.17.5", "@babel/plugin-transform-arrow-functions": "7.16.7", "@babel/plugin-transform-shorthand-properties": "7.16.7", "@babel/preset-typescript": "7.16.7", "@babel/runtime": "7.17.2", "@react-native-community/eslint-config": "3.0.1", "babel-jest": "27.5.1", "eslint": "8.9.0", "jest": "27.5.1", "metro-react-native-babel-preset": "0.68.0", "react-test-renderer": "17.0.2", "rn-nodeify": "10.3.0" }, "jest": { "preset": "react-native" }, "react-native": { "path": "path-browserify", "fs": "react-native-level-fs", "_stream_transform": "readable-stream/transform", "_stream_readable": "readable-stream/readable", "_stream_writable": "readable-stream/writable", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "stream": "stream-browserify", "tls": false }, "browser": { "path": "path-browserify", "fs": "react-native-level-fs", "_stream_transform": "readable-stream/transform", "_stream_readable": "readable-stream/readable", "_stream_writable": "readable-stream/writable", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "stream": "stream-browserify", "tls": false } }
@borisjwork here is my package.json file
{ "name": "AwsIoT", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint .", "postinstall": "npx rn-nodeify --install 'fs,util,path,tls,stream,buffer,global,process,events,url' --hack" }, "dependencies": { "asyncstorage-down": "^4.2.0", "aws-iot-device-sdk": "^2.2.11", "aws-sdk": "^2.1103.0", "buffer": "^4.9.2", "path-browserify": "^0.0.0", "process": "^0.11.10", "react": "17.0.2", "react-native": "^0.68.0", "react-native-fs": "^2.19.0", "react-native-level-fs": "^3.0.1", "readable-stream": "^1.0.33", "stream-browserify": "^1.0.0", "util": "^0.10.4" }, "devDependencies": { "@babel/core": "7.18.0", "@babel/runtime": "7.18.0", "@react-native-community/eslint-config": "2.0.0", "babel-jest": "26.6.3", "eslint": "7.32.0", "jest": "26.6.3", "metro-react-native-babel-preset": "0.67.0", "react-test-renderer": "17.0.2", "rn-nodeify": "^10.3.0" }, "jest": { "preset": "react-native" }, "react-native": { "path": "path-browserify", "fs": "react-native-level-fs", "_stream_transform": "readable-stream/transform", "_stream_readable": "readable-stream/readable", "_stream_writable": "readable-stream/writable", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "stream": "stream-browserify", "tls": false }, "browser": { "path": "path-browserify", "fs": "react-native-level-fs", "_stream_transform": "readable-stream/transform", "_stream_readable": "readable-stream/readable", "_stream_writable": "readable-stream/writable", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "stream": "stream-browserify", "tls": false } }
@avinashsahoo Have you get success ? if not then have you anything related to react native for integration ?
@avinashsahoo Have you get success ? if not then have you anything related to react native for integration ?
Yes, i was able to fix it. But not with client certificate (clientCert and caCert).
I created accesskey and secretly to access the service. like this.
const client = AWSIoTData.device({
region: 'ap-south-1',
host: 'xxxxxxxxxxxx.iot.ap-south-1.amazonaws.com',
clientId: 'example-client-id1234567',
protocol: 'wss',
maximumReconnectTimeMs: 5000,
debug: true,
accessKeyId: 'xxxxxxxxxxxx',
secretKey: 'xxxxxxxxxxxx',
});
@avinashsahoo thanks for the reply, but after provide all the details which you have mentioned in the block, I am getting
LOG using websockets, will connect to 'wss://xxxxxxxxx/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=xxxxxxx%2F20220630%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20220630T130253Z&X-Amz-SignedHeaders=host&X-Amz-Signature=xxxxxxxxx'...
LOG connection lost - will attempt reconnection in 15 seconds...
Try using earlier versions of IOT SDK containing different version of MQTT dependency.
The SDK uses MQTT under the hood to establish and transfer pub/sub messages.
I had a similar confusing bug where connection wasn't sustaining. And the issue was with the then latest-versioned MQTT lib.
@waleedshkt Can you please provide me the version number in which you get proper stable connection ?
Sure.
v2.2.6
Hello @alitele I have followed the steps, but it gives error because of shim.js while creating the signed apk from android studio. Would you mind helping me out with this?
Could we have detailed instructions on how to integration this with React Native?
Thanks