react-aws-iot-device-shadows v1.0.1
react-aws-iot-device-shadows
React Class wrapper for connecting to AWS IoT from a device using SDK JavaScript bundle ported from JamesJara's React Native Component
Allows developers to use the AWS IOT shadow support from a React class.
Overview
This document provides instructions on how to install and configure the AWS IoT device/Shadow in React.
AWS SDK Dependency
This package is built on top of the AWS SDK aws-sdk.js which provides two classes: 'device' and 'thingShadow'.
Thing Shadows
The 'thingShadow' class implements additional functionality for accessing Thing Shadows via the AWS IoT API; the thingShadow class allows devices to update, be notified of changes to, get the current state of, or delete Thing Shadows from AWS IoT. Thing Shadows allow applications and devices to synchronize their state on the AWS IoT platform.
Device
The 'device' class wraps mqtt.js to provide a secure connection to the AWS IoT platform and expose the mqtt.js interfaces upward. It provides features to simplify handling of intermittent connections, including progressive backoff retries, automatic re-subscription upon connection, and queued offline publishing with configurable drain rate.
Installation
Installing with npm:
npm install react-aws-iot-device-shadows
Example
./example/awsIOT.js - React Class example to serve as a Data Service within a React Application.
import AWSIot from "./example/awsIOT";
/*
Initialise service object, creates a
connection and subscribes to topics
*/
AWSIot.init();
// Publish a message to topic
AWSIot.publish('yourTopic', 'Hello world');
Add any logic you wish to perform on a message to the processEvent(event)
callback or specify your own callback function within the this.clent.setCallback()
function. Data can then be store within the class for access in a parent module.
## API Documentation
type
: use 'device' for device type and 'shadows' for ShadowThinghost
: the AWS IoT endpoint you will use to connectregion
: the AWS IoT region you will use to connectconfig
: extra configuration for the thingShadowonConnect
: callback for when the websockets connectsonReconnect
: callback for when the websockets reconnectsonDelta
: callback for delta msgonStatus
: callback for status msgonThingConnected
: callback for each registered thing
Connection Types
This react component only supports one type of connections to the AWS IoT platform:
- MQTT over WebSocket/TLS with SigV4 authentication using port 443
Re-Creating the bundle with webpack
This IOT JS SDK is packaged withwebpack, because currently there is not official support for AWS IOT react. This is already bundle it for you using the last version.
npm run build
Unit Tests
This package includes unit tests which can be run as follows:
npm test
Running the unit tests will also generate code coverage data in the 'reports' directory.
License
This react native component is distributed under the Apache License, Version 2.0, see LICENSE.txt and NOTICE.txt for more information.
Support
feel free to open any ticket in github issues