Giter VIP home page Giter VIP logo

react-native-aws-iot-device-shadows's Issues

Invalid connect options supplied

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:

screen shot 2017-11-24 at 16 43 58

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!!

onClose && onOffline ?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.