Skip to content

Commit

Permalink
Handle Scheduled Event
Browse files Browse the repository at this point in the history
Add environment variable “scheduledEventArn” and handle CloudWatch
scheduled events.
  • Loading branch information
cahaverl committed Feb 17, 2017
1 parent 6570876 commit 8e01b2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Binary file modified deploy.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ exports.handler = (event, context) => {
};

try {
// Check if this is a CloudWatch scheduled event.
if (event.source == "aws.events" && event["detail-type"] == "Scheduled Event") {
console.log(event);
// The environmnet variable scheduledEventArn should have a value as shown in the trigger configuration for this lambda function,
// e.g. "arn:aws:events:us-east-1:123123123:rule/scheduledNissanLeafUpdate",
if (event.resources && event.resources[0] == process.env.scheduledEventArn) {
// Scheduled data update
console.log("Beginning scheduled update");
car.getBatteryStatus(
() => console.log("Scheduled update requested"),
() => console.log("Scheduled update failed")
);
return;
}
sendResponse("Invalid Scheduled Event", "This service is not configured to allow the source of this scheduled event.");
return;
}
// Verify the person calling the script. Get your Alexa Application ID here: https://developer.amazon.com/edw/home.html#/skills/list
// Click on the skill and look for the "Application ID" field.
// Set the applicationId as an environment variable or hard code it here.
Expand Down

1 comment on commit 8e01b2b

@ccie6747
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the intention in this source to call "car.getBatteryStatus" for the scheduled event? I found when modifying to call car.sendUpdateCommand() I was able to get the scheduled event to populate the IOS App with a normal "Update" as performed from the iPhone on a scheduled basis. There were annoying alerts that started from the Nissan Portal - (sms/email) that I subsequently disabled.... but it worked. Opening the iPhone app - there is status updated within period of CloudWatch event trigger. As well, to note: The Nissan Connect Portal is NOT updated through this API call. You need to refresh from the web portal manually in order to update on the web interface of the EV @nissan.... but the iPhone App data is current based on scheduled call.

Please sign in to comment.