Skip to content

Instantly share code, notes, and snippets.

@johncmckim
Created September 4, 2016 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncmckim/1fdd91c5549a344074811c02ffb1e545 to your computer and use it in GitHub Desktop.
Save johncmckim/1fdd91c5549a344074811c02ffb1e545 to your computer and use it in GitHub Desktop.
Garden Aid - IoT - Moisture Check
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