jamesjara / react-native-aws-iot-device-shadows Goto Github PK
View Code? Open in Web Editor NEWReact Native Component for connecting to AWS IoT Shadows from a device using SDK JavaScript bundle
React Native Component for connecting to AWS IoT Shadows from a device using SDK JavaScript bundle
Hi,
Please see subject.
I see https://github.com/canhnht/react-native-aws-iot-device-shadows fork has lots of fixes to make this module actually work out of the box (extends React.Component etc.).
Thanks!
Hello!
I'm new using react-native and I'd like to develop a mobile application in react-native to interact with an AWSIoT shadow. I'm trying to use your lib but when I follow your example code I get this error:
my code can be seen below:
import React, {Component} from 'react';
import {
Platform,
Text,
View,
Button
} from 'react-native';
import styles from './styles'
import AWSIoTMQTT from '../../../node_modules/react-native-aws-iot-device-shadows/index.js';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
const accessKeyId = 'my_IAM_key_ID?';
const secretAccessKey = 'my_IAM_secret_key_ID?';
const sessionToken = ' ';
class DefaultScreen extends Component {
constructor(props) {
super(props);
this.state = {
answer: ' ',
device: {
deviceId: "my_device_id",
temp: 80
}
};
this.AWSIoTMQTT = null;
}
componentDidMount() {
// trigger STS credentials from Cognito Pool
this.AWSIoTMQTT.shadow.updateWebSocketCredentials(
accessKeyId,
secretAccessKey,
sessionToken
);
}
onConnect() {
this.AWSIoTMQTT.addThing(this.device.deviceId);
}
onDelta(thingId, stateObject) {
if (stateObject.state.device && stateObject.state.device.temp) {
this.updateState(thingId, {
temp: stateObject.state.temp
});
}
}
updateShadow(key) {
const current = this.data.device;
const update = {
[key]: ((Math.floor(Math.random() * (99 - 1)) + 1))
};
this.AWSIoTMQTT.shadow.update(current.deviceId, {
state: {
desired: update
}
});
}
onThingConnected(thingId) {
this.AWSIoTMQTT.shadow.get(thingId);
}
updateState(thingId, sensors) {
Object.assign(this.device, sensors);
this.setState({
device
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.js
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Text>
{this.state.answer}
</Text>
<AWSIoTMQTT
ref={(ref) => { this.AWSIoTMQTT = ref; }}
type="shadow"
region="us-east-2"
host="my_host"
onReconnect={() => this.onConnect()}
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); }}
/>
<Button
title = 'Update Shadow Randomly'
onPress={() => this.updateShadow('temp')}
/>
</View>
);
}
}
export default DefaultScreen
If you have any advice or tip to not hesitate to share it!
Thank you in advance!!
There is only example for type="shadow"
. Could you please give an example for type="device"
Hello,
I'm making a RN app and I would like to use a serverless infrastructure so I naturaly found your module.
I see in index.js that we have callbacks for those events but I don't see them in the doc.
Is there any particular reason for not encouraging users to use them ?
I'm not familiar at all with IoT and MQTT protocol.
Hi,
How to publish a message to a topic?. How to subscribe to multiple topics?. I could not find relevant documentation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.