Created
September 4, 2016 07:02
-
-
Save johncmckim/1fdd91c5549a344074811c02ffb1e545 to your computer and use it in GitHub Desktop.
Garden Aid - IoT - Moisture Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
const sns = new AWS.SNS(); | |
// Example event | |
// { DeviceId: 'test-js-device', Recorded: '2016-08-14T12:39:06.765Z', Level: 3.59334681998007 } | |
module.exports.checkLevel = (event, context, cb) => { | |
if(event.Level >= 2.5) { | |
cb(null, { message: 'No message to publish', event: event }); | |
return; | |
} | |
const params = { | |
Message: JSON.stringify({ | |
message: 'Moisture level has dropped to ' + event.Level | |
}), | |
TopicArn: process.env.mositureNotifyTopic | |
}; | |
sns.publish(params, cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment