Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid connect options supplied #3

Open
piloulac opened this issue Nov 24, 2017 · 1 comment
Open

Invalid connect options supplied #3

piloulac opened this issue Nov 24, 2017 · 1 comment

Comments

@piloulac
Copy link

piloulac commented Nov 24, 2017

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

@ronastlelobo
Copy link

Any luck @piloulac ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants