Gmail Buddy - Smarter Email Notifications

by shivamgautam in Circuits > Arduino

8134 Views, 148 Favorites, 0 Comments

Gmail Buddy - Smarter Email Notifications

Gmail Buddy - Smarter Notifications Device - RBL WiFi Micro
buddy2.jpg

What is Gmail Buddy?

It is a companion device which never lets you miss any important emails. It checks your inbox (Every 15 seconds) for new mails and notifies you using a sweet glow (Red Color). When you've checked you new mail, The light automatically goes OFF and a Yellow status LED (Yellow) goes ON. We'd be building this IoT device in very detailed step-by-step manner. Have Fun!

Its Features:-

  • Smarter Email Notifications. Never Miss an Email.
  • Power Efficient - powered by power efficient CC3200 based WiFi Micro Kit. ~ 30 Days battery Life!
  • A Cute Ergonomic Body Design.

Materials Required

354a0a4eed56835fe4f4eb97dc3866dd.image.530x397.jpg
51npebJ5E9L._SL1100_.jpg
CAT1509FIG10_sml.jpg
31Ukl-N1yGL.jpg
716OlhpFDtL._SL1100_.jpg

  1. RedBear Labs WiFi Micro Buy here
  2. Bi-Color/RGB LED x 1 Buy here
  3. 2N3904 NPN Transistor Buy here
  4. Female Headers Buy here
  5. Perfboard Buy here
  6. Jumper Wires Buy here
  7. AAA batteries x 3
  8. Switch

Tools Required:-

  1. Soldering Iron
  2. Hex Saw (To cut the perfboard)
  3. Helping Hands for soldering (Optional)

Building the Shield

Gmail-Buddy.png
IMG_20160228_200318575.jpg
IMG_20160228_200425274.jpg

First we need to build a shield to plugin our RedBear Labs WiFi Micro. This Shield will serve the power to the board, It will run our LED as a signal is generated by the board.

Build the circuit as shown in the schematics (1st image). We are making the following connections.

  1. We are connecting Yellow pin of the Bi-Color LED to Pin 6 on RBL WiFi Micro
  2. Red pin of Bi-Color LED to pin 7 by amplifying through 2n3904 transistor.
  3. The cathode pin of our LED to the GND on RBL WiFi Micro
  4. Connecting Vcc & Gnd leads to connect to our battery later.

Building the Power Supply

New-Project.png
IMG_20160227_123501256.jpg
IMG_20160227_123525732.jpg
IMG_20160227_123638813.jpg
IMG_20160228_200957039.jpg

Build a battery pack by connecting 3 AAA batteries in series as shown in the schematics. The Output voltage should be nearly around (1.5 x 3) 4.5 volts. If the batteries are new, The voltage might be higher ~ 4.8V. However the voltage is ideal to be connected to our RBL WiFi Micro Shield we've built in previous step.

Making Connections-

Connect the Vcc lead from the shield to + end through a switch and Gnd to the - end. Don't worry about the 3.3v I/P voltage of CC3200. The board have a linear voltage regulator which steps down our 4.5v supply to 3.3v to be used by the CC3200 module.

Setting Up Temboo & Google Developer Console

Screenshot (54).png
Screenshot (55).png
F1.jpg
L1.jpg
L2.jpg

We would be using Temboo to do all the heavy lifting for us. For those who don't know about Temboo- It is a IoT web service which takes care of all the API's in the backend & allow the developers to generate easy to use (If this than that) code.

Signup for Temboo here Its easy:)

Setting up Google Dev Console:-

To work with Gmail, we also need to signup at Google developer console, Signup & setup a project:-

  1. Name your project (anything you like:)
  2. Click on API & Auth. and enable Gmail API.
  3. Click on credentials and Create a new Client ID, Select WEB APPLICATIONS as the " Application Type " and hit Configure Consent Screen.
  4. Fill up all the required information and Save it.
  5. Now you will get some important credentials i.e ClientID & ClientSecret.
  6. Click edit settings and Edit Authorized redirect URIs and copy this

(https://{Your Temboo Account Name}.temboolive.com/callback/google

Enter your Temboo Acc name you've selected during signup.

Click Update

  • Go to Temboo Homepage and click on Library
  • Expand Google choreo.
  • Click on "OAuth" and then "InitialAuth"

Now we will Initialize our App and Here we will Also mention The services we will be using in the Scope block.

Select board as Texas instruments Launchpad and select TI CC3200 Launchpad (WiFi) as "How is it connected"

HERE we have two Blocks to Fill info in
1) Client ID – Goto to the Google Developer Page where we had just Created an APP and Copy the Client ID provided there

2) SCOPE – On the InitialAuth page Scroll Down there you will find VariousScopes , these Scopes are Basically the Services provided , you can choose the Service you want, just Copy that above in the Scope Block, use Spaces in between for more than one Scope we will be using the Gmail Inbox Feed scope used to read an Email on your Gmail Account.

Save your Profile by clicking SAVE PROFILE this will save your time by Auto-Filling the Info next time you use it. Copy and paste the scope Above and Hit " RUN "

This will generate two things

1) AuthorizationURL

2) CallBackID

Granting Access To temboo of your Google Application and Generating an Access Token

  • Follow the Instructions Generated in the Output, and Open that Link in a new TAB
  • Now Google will Ask for your permission, Click on ACCEPT.
  • Now if a Blank Page Shows Up, than it means Everything is Fine till Now and Temboo Have the rights to Read your Emails through your Created APP.

Output from the InitialAuth as Shown in the Image , will be used in FinalAuth Page

Goto FinalizeAuth page by clicking on the Link in the Output, there you will find 3 blocks to fill

  1. Client ID ---- Provided on The Google’s App Developer page
  2. Client Secret ---- Also on the Google’s App Developer page
  3. CallBackID ---- Copy it from the InitialAuth page

Now Click on "Run". It will Generate an Access Token which we'll be using in our code.

Uploading the Code

IMG_20160228_202201223.jpg
Screenshot from 2016-02-28 20_28_34.png

Now, It's the time to upload code to our WiFi Micro board. Download the attached code sketches.

  1. Gmail_buddy.ino

#include <WiFi.h>

#include <WiFiClient.h>

#include <Temboo.h>

#include "TembooAccount.h" // Contains Temboo account information

WiFiClient client;

// We limit this so you won't use all of your Temboo calls while testing int maxCalls = 50;

// The number of times this Choreo has been run so far in this sketch int calls = 0;

int outputPin = 7;

void setup() { Serial.begin(9600); int wifiStatus = WL_IDLE_STATUS;

// Determine if the WiFi Shield is present Serial.print("\n\nShield:"); if (WiFi.status() == WL_NO_SHIELD) { Serial.println("FAIL");

// If there's no WiFi shield, stop here while(true); }

Serial.println("OK");

// Try to connect to the local WiFi network while(wifiStatus != WL_CONNECTED) { Serial.print("WiFi:"); wifiStatus = WiFi.begin(WIFI_SSID, WPA_PASSWORD);

if (wifiStatus == WL_CONNECTED) { Serial.println("OK"); } else { Serial.println("FAIL"); } delay(5000); }

// Initialize pins pinMode(outputPin, OUTPUT);

Serial.println("Setup complete.\n"); }

void loop() { if (calls < maxCalls) { Serial.println("Calling GetUnreadMail Choreo..."); runGetUnreadMail(); calls++; } else { Serial.println("Skipping to save Temboo calls. Adjust maxCalls as required."); } delay(60000); }

void runGetUnreadMail() { TembooChoreo GetUnreadMailChoreo(client);

// Set Temboo account credentials GetUnreadMailChoreo.setAccountName(TEMBOO_ACCOUNT); GetUnreadMailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); GetUnreadMailChoreo.setAppKey(TEMBOO_APP_KEY);

// Set profile to use for execution GetUnreadMailChoreo.setProfile("GmailProfile"); // Identify the Choreo to run GetUnreadMailChoreo.setChoreo("/Library/Google/Gmail/GetUnreadMail");

// Run the Choreo unsigned int returnCode = GetUnreadMailChoreo.run();

// A return code of zero means everything worked if (returnCode == 0) { while (GetUnreadMailChoreo.available()) { String name = GetUnreadMailChoreo.readStringUntil('\x1F'); name.trim();

String data = GetUnreadMailChoreo.readStringUntil('\x1E'); data.trim();

if (name == "FullCount") { if (data.toInt() >= 1) { digitalWrite(outputPin, HIGH); } else{ digitalWrite(outputPin, LOW); } } } }

GetUnreadMailChoreo.close(); }

2. TembooAccount.h

/*
IMPORTANT NOTE about TembooAccount.h

TembooAccount.h contains your Temboo account information and must be included alongside your sketch. To do so, make a new tab in Energia, call it TembooAccount.h, and copy this content into it. */

#define TEMBOO_ACCOUNT "YourAcountNameHere" // Your Temboo account name #define TEMBOO_APP_KEY_NAME "YourAppNameHere" // Your Temboo app name #define TEMBOO_APP_KEY "YourAppKeyHere" // Your Temboo app key

#define WIFI_SSID "YourWiFiName" #define WPA_PASSWORD "YourWiFiPassword"

/* The same TembooAccount.h file settings can be used for all Temboo sketches.

Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */

Change the credentials in the TembooAccount.h like your Temboo Account Name, Temboo App Name and the App Key we've generated in previous step.

Upload the code to your RBL WiFi Micro by plugging it into the MK20 USB dongle bundled with the kit.

Finalize

gmailBuddy.jpg
IMG_20160228_112053051.jpg
IMG_20160228_150055004.jpg

Now we've built our shield, Set up Temboo, Google Dev Console, Uploaded the code. It's time to finalize our Gmail Buddy.

  • Plugin the RBL WiFi board into the shield we've built.
  • Stack the shield on the battery pack using double sided tape
  • Place the whole circuit into a sweet plastic box.
  • Switch ON the power supply and close the box.

Your First IoT Device is ready to roll!

It will notify you every time a mail hits your inbox. Feel free to ask for any help. Give suggestions. It's my very first instructable. I've tried to be as brief as possible. If you like it please vote this instructable.