const thingShadow = require('./thing'); const isUndefined = require('./common/lib/is-undefined'); const cmdLineProcess = require('./examples/lib/cmdline'); function processTest( args, argsRemaining ){ if(isUndefined( args.thingName )){ console.log( 'thing name must be specified with --thing-name'); process.exit(1); } const thingShadows = thingShadow({ keyPath: args.privateKey, cerPath: args.clientCert, caPath: args.caCert, clientId: args.clientId, region:args.region, reconnectPeriod: args.recconectPeriod, }); thingShadows.on('connect',function(){ console.log('connected to things instance, registering thing name'); thingShadows.register( args.thingName, { persistentSubscribe: true }); }); thingShadows.on('close', function() { thingShadows.unregister( args.thingName ); console.log('close'); }); thingShadow.on('reconnect', function() { thingShadows.register( args.thingName, { persistentSubscribe: true }); console.log('offline'); }); thingShadows.on('error', function(error){ console.log('error', error); }); thingShadows.on('delta', function(thingName, stateObject){ console.log('received delta on '+thingName+':'+ JSON.stringify(stateObject)); thingShadows.update( thingName, { state: { reported: stateObject.state }}); }); thingShadows.on('timeout', function(thingName, clientToken){ console.warn('timeout: '+thingName); }); } module.exports = cmLineProcess; if (require.main === module){ cmdLineProcess('connect to the AWS IoT service and perform thing shadow sample', process.argv.slice(2), processTest, '', true) }

