Clockwise is your next intelligent alarm clock: it wakes you up by saying out loud the weather conditions and your Google Calendar events for the day in a Bluetooth speaker.
The base of this project is a python script: using APIs, like pywapi (API for weather report in python), Google Calendar API (to fetch the events), and VoiceRSS (text-to-speech REST API), to gathers useful information and say it out loud in a Bluetooth speaker, so you can make your daily plans without even getting out of bed! This can be helpful for blind or disabled people, and future versions of this project may be gesture controlled (using Intel Real Sense), instead of having actual buttons.
How it works: you set an event in your Google Calendar called 'Alarm' to happen everyday at the time you want Clockwise to wake you up. When the time comes, a ringtone, chosen by you, will start playing in a Bluetooth speaker, and you can press a Grove button to stop it, or the other one to snooze it. If you snooze, it will wait a couple minutes and after that it'll start ringing again. When you finally press stop, a report, consisting of some weather informations (local temperature, maximum and minimum temperature for the day, local forecast, and chance of rain), and the events for the day, set in your Google Calendar account, will be spoken in the Bluetooth speaker, so you won't miss anything from your agenda!
Powered by Intel Edison and using the Grove Starter Kit IoT Edition, this project was developed at Intel IoT Roadshow 2015 in November/2015 at São Paulo, Brazil.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Components
We're going to need:
- Intel Edison with Arduino Breakout Board (the Mini Breakout board should work as well)
- 2 USB cables
- 2 Grove push buttons (regular buttons should work)
- Grove base shield (if you're using Grove push buttons)
- Bluetooth speakers
How to set everything up:
- Assemble the Grove base shield on top of the Intel Edison Arduino Breakout Board, and connect the push buttons on D3 and D4 in the base shield.
- Connect the USB cables on the two mini-usb ports in the Arduino Breakout Board and flip the switch next to it towards the mini-usb port. Connect the cables to your computer.
- Turn the Bluetooth speakers on and set it to pairing mode.
Step 2: Setting Up Edison
If this is the first time you're using the Intel Edison, you're going to need to configure it first.
Things you have to do:
- Stablish a serial connection to the board
- Update the firmware to the latest version (highly recommended)
- Set a root password to enable ssh (this is needed in order to use scp to copy files from your pc to the board)
Get the board online via wifi
If you don't know how to set these things up, you can follow the Sparkfun Getting Started Guide.
Once you've done it, next thing to do is connecting the board to the Bluetooth speaker.
Step 3: Connect to Bluetooth Speaker
The Bluetooth speaker is going to be used to reproduce the waking up sound and saying the weather report.
In order to stablish the connection to the speaker and get it it working, you can follow this tutorial. Once you get to the gStreamer part, go to next step where we're are going to configure the packages needed.
Note: you're going to need to follow these steps every time you reboot the board. If you want, you can write a start up script that connects the board to the speaker when it boots.
Step 4: Configuring the Packages
We'll use the following packages in the python script:
- httplib2 (pip install httplib2)
- apiclient (pip install google-api-python-client)
- oauth2client (pip install oauth2client)
- pywapi (instructions here)
- unirest (pip install unirest)
Since pip is not in the official repositories, we need to add the unofficial repositories.
How to install pip from the unofficial repos:
- Begin by adding the repositories using vi (vi /etc/opkg/base-feeds.conf)
- Add the following three lines:
- wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
- python ez_setup.py --no-check-certificate
Now you can download the needed packages.
Next step is configuring gStreamer to reproduce mp3. To do so, we'll have to create our own repository to download the plugins, since it's not in the unofficial repositories.
Step 5: Using GStreamer to Reproduce Mp3
To reproduce mp3 in Edison we'll use gStreamer and the plugins gst-plugins-ugly and gst-plugins-ugly-mad. Since you can run into trouble distributing them, they're not included in the unofficial repositories for Intel Edison, so we'll set up our own repository.
First, install gStreamer using opkg (opkg install gstreamer1.0)
Then, in order to set our own repository, you'll have to find out how it's done, since I can't find a reliable way to do so...
Once you get used to preparing packages using bitbake, create the plugins listed above and install them on Edison.
To check if everything is in order, try reproducing a .mp3 file using the command:
gst-launch-1.0 filesrc location=/home/root/test.mp3 ! mad ! pulsesink
If you successfully connected the Bluetooth speaker, you'll be able to listen to the .mp3
Step 6: Configure Access to Google Calendar API
To fetch the events for the day, we'll use the Google Calendar API.
Steps needed to get it up and running:
- Turn on the Google Calendar API:
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API.
- Click Continue, then Go to credentials.
- At the top of the page, select the OAuth consent screen tab.
- Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Add credentials button and select OAuth 2.0 client ID.
- Select the application type Other, enter the name "Clockwise", and click the Create button.
- Click OK to dismiss the resulting dialogue.
- Click the (Download JSON) button to the right of the client ID.
- Move this file to your working directory and rename it client_secret.json.
- Install the Google Client Library
- Run the following command to install the library using pip: pip install --upgrade google-api-python-client
Save the client_secret.json file, we'll need it later.
Step 7: Using the Text-to-speech API
To say out loud the report, we'll use an API that convert text to speech.
- Create an account at http://www.voicerss.org/.
- Copy your API Key
- Proceed to Mashape Marketplace and create an account there too
- In the page of Voice RSS API at Mashape, click in "Convert text to speech via HTTP POST"
- Paste your API Key from Voice RSS in the Key field
- In the right, click in Python, then copy your "X-Mashape-Key"
Save your keys somewhere, as you'll have to input them in the source code.
Step 8: Downloading the Source Code
The source code is available at my GitHub account: https://github.com/julianaklulo/clockwise
- Create a directory 'clock' in /home/root
- Download calendar_API.py, intelligent_clock.py and wake.mp3 from my GitHub repo.
- Locate the client_secret.json file you downloaded in the step Configuring the Google Calendar API.
- Transfer those files to the Edison board using scp to copy them over the internet (tutorial here).
In the intelligent_clock.py file, substitute the keys in the generate_mp3 function (the ones you saved in the previous step).
Step 9: Make It Work
Let's check if we have done all that it takes for it to work:
- Connected the Edison board to wifi
- Connected the Bluetooth speaker to the board
- Downloaded and installed the packages
- Downloaded the gStreamer plugin to reproduce mp3
- Configured the Google Calendar API and downloaded the client_secret.json file
- Created an account at Voice RSS website and generated the API Key
- Created an account at Mashape Marketplace and generated the X-Mashape-Key
- Downloaded the source code from GitHub and pasted your keys in intelligent_clock.py
- Transferred the files to the board via scp
Now that we have set everything, let's run the script: python intelligent_clock.py
By default, the alarm is set to one minute after the script is run. To change the time, you have to insert an event in the Google Calendar account configured in the API called 'Alarm', and set it to happen everyday.
When the time comes, you should hear the wake.mp3 file being reproduced in the Bluetooth speaker. Press the stop button to listen to the report generated by the Voice RSS API, or snooze to delay it in one minute. If you want to end the snooze time and listen to the report, just hit stop button again and it should be reproduced in the speakers.
Step 10: That's It
By now, you should be able to make your own Clockwise!
If you find out how to set the repository to download the gStreamer plugins, please let me know! I haven't found an reliable method to do it and would really appreciate some help!
Thank you for reading through!