Skip to content

Latest commit

 

History

History
91 lines (72 loc) · 5.32 KB

ExampleREADME.md

File metadata and controls

91 lines (72 loc) · 5.32 KB

AmazonDRS Examples

This document describes the example applications provided with the AmazonDRS library.

Replenish example

The example:

  • authenticates the device on Amazon platform using the provided Client ID and Client Secret
  • executes the following cycle: places an order, waits for 8 sec, cancels the order, waits for 12 sec
  • logs all responses received from the Amazon DRS

Source code: Replenish.agent.nut

Example Setup and Run

Login To Amazon

Login to Amazon Developer Services. If you are not registered as a developer, create a developer's account.

Set Up Imp Device

  1. Set up a device
  2. In the Electric Imp's IDE create new Product and Development Device Group.
  3. Assign the device to the newly created Device Group.
  4. Copy the Replenish example source code and paste it into the IDE as the agent code.
  5. Make a note of the agent's URL. It will be required for the next steps. Make a note of the agent's URL
  6. Leave impCentral open in your browser — you will be returning to it later.

Create an LWA Security Profile

This stage is used to authenticate the imp application in Amazon.

  1. Launch your Amazon Developer Console.
  2. Click on the APPS & SERVICES tab, then click Login with Amazon. LWA
  3. Click Create a New Security Profile. Create a New Security Profile
  4. Enter the following information:
    1. Security Profile Name: example_sp
    2. Security Profile Description: example_sp_desc
    3. Consent Privacy Notice URL: https://example.com
  5. Click Save. Enter required information and click Save
  6. Then you'll be taken to your list of security profiles. Click the gear next to the Security Profile you created and select Security Profile. Click the gear next to the Security Profile you created and select Security Profile
  7. Make a note of your Client ID and Client Secret. Make a note of your Client ID and Client Secret
  8. Then click on the Web Settings tab and enter the agent's URL into the Allowed Return URLs field. Enter the agent's URL into the Allowed Return URLs
  9. Click Save.
  10. Do not close this page.

Note: any LWA Security Profile works only for the one agent the URL of which you entered in the Allowed Return URLs field.

Create a device

  1. In the Amazon Developer Console, click the APPS & SERVICES tab and choose Dash Replenishment Service. Open Dash Replenishment Service
  2. Click the CREATE A DEVICE button.
  3. In the appeared window, fill in the fields:
    1. Name: example_device
    2. Model ID: example_model Fill in the fields
  4. Click Save.
  5. Open the Slot Localization tab and make a note of Slot ID. Make a note of Slot ID

Adding API Keys to Your Agent Code

  1. Return to impCentral.
  2. Find the AMAZON DRS CONSTANTS section at the end of the agent code, and enter the Client ID, Client Secret and Slot ID from the steps above as the values of the AMAZON_DRS_CLIENT_ID, AMAZON_DRS_CLIENT_SECRET and AMAZON_DRS_SLOT_ID constants, respectively. In impCentral, set the constants in the agent code
  3. Again, do not close impCentral.

Build and Run the Electric Imp Application

  1. Click Build & Run All to syntax-check, compile and deploy the code.
  2. On the log pane, you should see Log in please message. This example uses OAuth 2.0 for authentication, and the agent has been set up as a web server to handle the authentication procedure.
    1. Click the agent URL in impCentral. In impCentral, click the Build and Run All button to compile and deploy the application and begin device and agent logging
    2. You will be redirected to the login page.
    3. Log into Salesforce on that page.
    4. If login is successful, the page should display Authentication complete - you may now close this window.
    5. Close that page and return to impCentral.
  3. Make sure there are no errors in the logs.
  4. Make sure there are periodic logs like this: Make sure there are periodic logs like this
  5. Your application is now up and running.
  6. You may check that the value of the My_Timestamp__c field in the received event is equal to the value in the sent event.