Jar is the most used thing in our kitchen and yet it is so dumb. We use it to store Tea, Coffee, Cereals and Rice, Dals and Pulses, Flours, Oils and unending list of groceries. In today’s busy world it is very cumbersome to prepare a grocery list manually of all those kitchen items which are running low. Everyone has a couple of things they buy frequently, the same thing every time. Wouldn’t it be better if those most useful things that we really don’t want to run out of are automatically ordered? We all hate the “ran out of it” moment.
So here is the solution: OmegaJar - An internet connected smart jar.
It is built using ESP8266 ( NodeMCU - A Microcontroller with Wi-Fi capability) and Load cell weighing sensor so that the user can track what’s inside and what it means for your health. It will shop when you are running low via Amazon DRS and remind you the same. And every time something gets ordered, you get a notification on your phone through the Amazon. The battery status is also notified to the user.
Amazon Dash Replenishment Service (DRS) allows connected devices to leverage Amazon's retail platform to build automatic reordering experiences for your customers. DRS enables connected devices to order physical goods from Amazon when supplies are running low. Customers just needs to link their Amazon account, and select the products (from the available options) they want to automatically reorder.
WS2812B LED is used on the jar to notify you the quantity of the grocery inside the jar whether it is running low or has sufficient quantity or full. It is also used to show when the product is being replenished or whether device is connected to Internet. The jar will also help you keep track of Expiry date. And of course you will never run out of anything. As the data will be transmitted online you can have real time insight into nutrition from anywhere. No last-minute shopping trips or calls for delivery.
The App will show real-time charge on each of your jars and will provide alerts if the charge is running low. When required, plug in the micro USB cable and attach to your computer or wall socket. An indicator will light up when charged. It will help you turn your kitchen into a smart one.
Why ESP8266?ESP8266 is transforming the world with its low cost and high features which makes it an ideal module for Internet Of Things (IOT). It can be used in any application where you need to connect a device to your local network or internet. It is a low-cost Wi-Fi chip with full TCP/IP stack and MCU (Micro Controller Unit) capability. Using Deep Sleep Mode significantly reduces the power consumption of ESP8266 boards, so you can build projects that will last for months on a single battery.
Steps to Follow if you too want to build the same project:-1) Sign in to Amazon Developer and AWS AccountYou require amazon account credentials to sign in to Amazon Developer or AWS account.
Signup for Amazon Developer and AWS Account:
- Link of Amazon Developer: developer.amazon.com
- Link of AWS: aws.amazon.com
1. Login into Amazon Developer Portal
Link: developer.amazon.com
2. Click on Apps and Services
3. Click on Login with Amazon and there Click on Create a New Security Profile
4. Complete the details in the Security Profile and Click Save
5. Now Under Login with Amazon you will see your completed Security Profile
6. Here On the Right Side You see Manage. Click Web Settings which is located on Manage Settings.
7. Fill the Web Setting Details and note down the Return URL have entered here!
8. Then Click on General Tab to note down following details:
- Client ID,
- Security Profile ID,
- Client Secret,
So you now have following details with you:-
- Client ID,
- Security Profile ID,
- Client Secret,
- Return URL.
The Dash Replenishment Service (DRS) uses SNS Topics to notify you (the device maker) of changes to device status, order state, subscription status, and more. Amazon’s Simple Notification Service (SNS) is a pub-sub service from AWS that makes it easy to set up, manage, and send messages instantly to applications or users.
1. Login into Amazon Web Services Account
Link: console.aws.amazon.com
2. Click on Services tab and Search for SNS service
3. Click on Create Topic in the SNS Dashboard
4. After clicking on Create Topic a popup for SNS will be displayed. Enter Topic Name and Display name respectively. After writing this click Create Topic button.
5. Click on My Account:
6. Copy your Account ID from Account Settings:
7. Click on Edit Topic Policy as shown in the below image:
8. Choose the option of "Only these AWS users" and then write AWS Account ID in the given box and click Update Policy button.
9. Note down the AWS SNS ARN(Amazon Resource Number) located in Topics.
10. Click Create subscription.
11. In the Topic ARN field, paste the topic ARN you created in the previous task. In the Protocol drop-down box, select Email. In the Endpoint box, type an email address you can use to receive the notification. Click Create subscription.
1. Login to Amazon Developer Portal
Link: developer.amazon.com
2. Go to "Dash Replenishment Service" which is located in Apps & Services
3. Register with LWA and paste security profile ID and click Next
4. Click Next
5. Enter SNS ARN topic ID and click Next
6. Done!!
7. After Setting up DRS with your account/security profile ID, then you need to create Device in DRS.
8. Add your Device and then Click on Next
9. Provide a friendly name for your slot and add products to it by searching for them by ASIN. ASINs are Amazon's version of unique product identification. The items you add here are for testing your device and replenishment orders. This does not have to be your final list of ASINs and you can change this information later.
ASIN is an identifier that Amazon gives to every single product on amazon.com. It is an alphanumeric string and that can be found in the “Product Details” section on any product detail page.
It is important that any product you want your device to reorder meets two criteria: 1. The item is available on amazon.com 2. The item is “Shipped and Sold” by Amazon.com.
E.g. Image see below:-
Then enter those ASIN here in Add slots to your device and click on Next
10. Capture Slot ID and Model ID you will require it afterwards
1) Create a repository
2) Upload the website codes, images and required Javascript files
3) Commit and You're Done
Fire up a browser and go to http://username.github.io.
4) My Product Registration Page {https://alpha-amol.github.io} :
Click on Login with Amazon to get Authorization code required by the Hardware to place order:Amazon
Choose Product From Slot which you want to re-order automatically and then click Next:
Enter your Address and Payment Details and Complete the Setup
After Completing the Setup you will be re-directed to your Product Registration page with the Authorization Code:-
Also you will receive a mail notification specifying that
"Thanks for choosing Amazon Dash Replenishment,
The products below will be automatically reordered before you run out. You will receive an email from Amazon when an order is placed and you can modify or cancel automatic reordering any time".
HTML Code Explanation:
Your need Product Model ID and a Serial no. (Can be any unique name just to identify your device):
<b>PRODUCT MODEL ID </b> <br /> <input maxlength="36" name="pname" size="38" style="text-align: center;" type="text" value="OmegaJar" /><br /><br />
<b>SERIAL NO </b><br /> <input maxlength="12" name="sname" size="14" style="text-align: center;" type="text" value="OmegaJarByESP8266" /><br /><br />
When you click on Login with Amazon button on Product registration page the following function is executed:
function lwaFunction() {
var str = String(window.location);
var pos = str.indexOf("code=");
if(pos == -1)
{
var x1 = document.getElementById("frm1");
var productid = String(x1.elements[0].value);
var serialno = String(x1.elements[1].value);
window.open("https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.a94c174e2a7bfd690d602f8ea&scope=dash%3Areplenish&scope_data=%7B%22dash%3Areplenish%22%3A%7B%22device_model%22%3A%22"+productid+"%22%2C%22serial%22%3A%22"+serialno+"%22%2C%22is_test_device%22%3Atrue%7D%7D&response_type=code&redirect_uri=https%3A%2F%2Falpha-amol.github.io");
}
}
window.open in the above function opens a URL which takes us to Login With Amazon page for Authorization Code Grant generation. the details of theURL is as follows:-
- client_id: amzn1.application-oa2-client.c0a2100c1af289b1bf4011c71f6029b3 (from the LWA Security Profile)
- scope: dash:replenish. (DRS always uses this scope)
- scope_data:
{"dash:replenish":{"device_model":"
OmegaJar","serial":"
OmegaJarByESP8266", "is_test_device":"true"}}
- device_model: Arduino_dash (Model ID from the "Create Dash Replenishment Step")
- serial: OmegaJarByESP8266 (Make this up! It's supposed to uniquely identify your hardware.)
- response_type: code (Code, because we're asking for an authorization_code which we'll use to gain tokens for API access)
You'll notice that not all field values change when they are URI encoded, only the scope and redirect_uri actually change. When composing your request url you can use this handy encoder/decoder to quickly encode your values. If you've composed everything correctly paste the encoded url into the browser and it should bring you to an Amazon login page where you'll log in and authorize your device for replenishment.
Copy the Authorization code so as to use it the Esp8266 code to replenish the items running low.
6) Hardware Build (Firmware and Circuit Connections)Amazon DRS Parameters Required in ESP8266/NodeMCU code:-
//AMAZON DRS parameters
const char* device_model = "OmegaJar"; //Product model ID of your device
const char* device_identifier = "OmegaJarByESP8266"; // Serial No of device any thing you wish at production end
const char* client_id = "amzn1.application-oa2-client.a94c174e2a7e4d6686bfd690d602f8ea"; // your Amazon developer account client ID
const char* client_secret = "744e08848dee38a8df1d228d77ffc93d5390ddf55962a5d6bca77fb7476edbcc"; // Your Amazon developer account secret code
const char* slot_id = "be3e0bdf-66d1-46a0-b1a6-54fe6523bad1"; //Sloat ID for your product
const char* redirect_uri = "https%3A%2F%2Falpha-amol.github.io"; //Encoded Return URL should be encoded and same as used at time of device creation
Now you need to understand first how DRS works:-
1) You will need to Login with Amazon from the Product Registration page to get authorization grant code.
2) For the first time in your Microcontroller code you will use this authorization grant code to generate Refresh Token.
3) Every time you need to replenish a product you need Access token so you will use this Refresh token and generate Access token before replenishing the product
4) After you got the Access token call the DRS Replenish API via the microcontroller to replenish the product running low.
String authorization_grant_code = ""; //ex: ANQEgiAOjkQWjKvhNWIN
String refresh_Token = "";
String access_Token = "";
The above variables store the Authorization grant code, Refresh Token and Access token inside a function (DRS API) temporarily.
Whenever you run the ESP8266 code it waits for a pressing a Config button in case you need to change either SSID and Password of Access point or Authorization grant code. As soon as you press the Grove Touch sensor based Config Button the ESP8266 forms it's own webserver:-
wifiManager.startConfigPortal("OmegaJar")
There it will wait for any device to get connected to it. If someone gets connected he/she can change the SSID/Password/Authorization grant code.
Output on Serial Monitor During those process
Comments