alexa-iot-helper
v1.0.12
Published
Work with aws-iot-client. The alexa-iot-helper is used to simply update device state on thing shadow. Currently, support monitor on\off, media player control, system shutdown
Downloads
3
Readme
alexa-iot-helper
Work with aws-iot-client. The alexa-iot-helper is used to simply update device state on thing shadow.
Currently, support monitor on\off, media player control, system shutdown
Installation
npm install alexa-iot-helper
API
var alexaIotHelper = require('alexa-iot-helper');
ctrMonitor(iotdata)
Create a new ctrMonitor
object by the given iotdata
.
For example, assume we want to create an iot-helper object to control our monitor, we can use the following code
var alexaIotHelper = require('alexa-iot-helper').ctrMonitor;
var monitor = new alexaIotHelper(iotdata);
ctrMediaPlayer(iotdata)
Create a new ctrMediaPlayer
object by the given iotdata
.
For example, assume we want to create an iot-helper object to control our music player, we can use the following code
var alexaIotHelper = require('alexa-iot-helper').ctrMediaPlayer;
var player = new alexaIotHelper(iotdata);
.ctrMonitor.turnOff(clientId, callback)
Update thingshadow by clientId
for monitor off and process callback
function.
.ctrMonitor.turnOn(clientId, callback) {
Update thingshadow by clientId
for monitor on and process callback
function.
.ctrMediaPlayer.play(clientId, callback) {
Update thingshadow by clientId
for passing play
message to the media player and process callback
function.
.ctrMediaPlayer.pause(clientId, callback) {
Update thingshadow by clientId
for passing pause
message to the media player and process callback
function.
.ctrMediaPlayer.next(clientId, callback) {
Update thingshadow by clientId
for passing next
message to the media player and process callback
function.
.ctrMediaPlayer.pre(clientId, callback) {
Update thingshadow by clientId
for passing pre
message to the media player and process callback
function.
ctrSystem(iotdata)
.ctrSystem.shutdown(clientId, callback)
Update thingshadow by clientId
for system shutdown and process callback
function.
.ctrSystem.shutdownAsync(clientId, callback)
Update thingshadow by clientId
for system shutdown asynchronizely
Examples
This simple example shows how to use alexa-iot-helper
to change device status on the cloud.
First, we create the object of the iotdata via aws-sdk with particular endpoint loaded from iotConfig.json
//iotConfig.json
{
"endpoint": "ef3423d1pm93tna.iot.us-east-1.amazonaws.com"
}
After that, inject iotdata into alexaIotHelper
.
Here is the sample code.
/* Initialize */
//require aws sdk
var AWS = require("aws-sdk");
AWS.config.update({ region: 'us-east-1' });
//create iotdata object
const endpoint = require('./iotConfig');
var iotdata= new AWS.IotData(endpoint);
//require alexa-iot-helper
// and create an object for monitor control
var alexaIotHelper = require('alexa-iot-helper').ctrMonitor;
var monitor = new alexaIotHelper(iotdata);
//monitor control, update device status on cloud
monitor.turnOn("clientId", function () {
//Do something
});
Release Note:
v1.0.12
Support Shutdown system asynchronizely