Introduction
This smart alarm clock application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison development platform, cloud platforms, APIs, and other technologies.
From this exercise, developers will learn how to:
- Connect the Intel® Edison development platform, a computing platform designed for prototyping and producing IoT and wearable computing products.
- Interface with the Intel® Edison platform IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
- Run this code sample in Intel® System Studio IoT Edition. Intel® System Studio lets you create and test applications on Intel-based IoT platforms.
- Set up a web application server to set the alarm time and store this alarm data using Azure Redis Cache* from Microsoft Azure*, Redis Store* from IBM Bluemix*, or ElastiCache* using Redis* from Amazon Web Services* (AWS), different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly.
- Invoke the services of the Weather Underground* API for accessing weather data.
What it is
Using an Intel® Edison board, this project lets you create a smart alarm clock that:
- can be accessed with your mobile phone via the built-in web interface to set the alarm time.
- displays live weather data on the LCD.
- keeps track of how long it takes you to wake up each morning, using cloud-based data storage.
How it works
This smart alarm clock has a number of useful features. Set the alarm using a web page served directly from the Intel® Edison board, using your mobile phone. When the alarm goes off, the buzzer sounds, and the LCD indicates it’s time to get up. The rotary dial can be used to adjust the brightness of the display.
In addition, the smart alarm clock can access daily weather data via the Weather Underground* API and use it to change the color of the LCD. Optionally, all data can also be stored using the Intel IoT Examples Data store running in your own Microsoft Azure* account.
Hardware requirements
Grove* Starter Kit Plus containing:
- Intel® Edison platform with an Arduino* breakout board
- Grove* Rotary Analog Sensor(http://iotdk.intel.com/docs/master/upm/java/classupm__grove_1_1_grove_rotary.html)
- Grove Buzzer (http://iotdk.intel.com/docs/master/upm/java/classupm__buzzer_1_1_buzzer.html).
- Grove Button (http://iotdk.intel.com/docs/master/upm/java/classupm__grove_1_1_grove_button.html)
- Grove RGB LCD (http://iotdk.intel.com/docs/master/upm/java/classupm__i2clcd_1_1_jhd1313m1.html)
Software requirements
- Intel® System Studio IoT Edition
- MMicrosoft Azure*, IBM Bluemix*, or AWS account (optional)
- Weather Underground* API key
How to set up
To begin, clone the How-To Intel IoT Code Samples repository with Git* on your computer as follows:
$ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git
To download a .zip file, in your web browser go to https://github.com/intel-iot-devkit/how-to-code-samples and click the Download ZIP button at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example.
Adding the program to Intel® System Studio IoT Edition
** The following screenshots are from the Alarm clock sample, however the technique for adding the program is the same, just with different source files and jars.
Open Intel® System Studio IoT Edition, it will start by asking for a workspace directory. Choose one and then click OK.
In Intel® System Studio IoT Edition , select File -> new -> Intel(R) IoT Java Project:
Give the project the name "AlarmClock" and then click Next.
You now need to connect to your Intel® Edison board from your computer to send code to it. Choose a name for the connection and enter IP address of the Intel® Edison board in the "Target Name" field. You can also try to Search for it using the "Search Target" button. Click finish when you are done.
You have successfully created an empty project. You now need to copy the source files and the config file to the project. Drag all of the files from your git repository's "src" folder into the new project's src folder in Intel® System Studio IoT Edition. Make sure previously auto-generated main class is overridden.
The project uses the following external jars: gson-2.6.1, jetty-all-9.3.7.v20160115-uber, joda-time-2.9.2. These can be found in the Maven Central Repository. Create a "jars" folder in the project's root directory, and copy all needed jars in this folder. In Intel® System Studio IoT Edition, select all jar files in "jars" folder and right click -> Build path -> Add to build path
Now you need to add the UPM jar files relevant to this specific sample. right click on the project's root -> Build path -> Configure build path. Java Build Path -> 'Libraries' tab -> click on "add external JARs..."
for this sample you will need the following jars:
- upm_buzzer.jar
- upm_grove.jar
- upm_i2clcd.jar
The jars can be found at the IOT Devkit installation root path\iss-iot-win\devkit-x86\sysroots\i586-poky-linux\usr\lib\java
Connecting the Grove* sensors
You need to have a Grove* Shield connected to an Arduino*-compatible breakout board to plug all the Grove devices into the Grove Shield. Make sure the tiny VCC switch on the Grove Shield set to 5V.
- Plug one end of a Grove cable into the Grove Rotary Analog Sensor, and then connect the other end to the A0 port on the Grove Shield.
- Plug one end of a Grove cable into the Grove Button, and then connect the other end to the D4 port on the Grove Shield.
- Plug one end of a Grove cable into the Grove Buzzer, and then connect the other end to the D5 port on the Grove Shield.
- Plug one end of a Grove cable into the Grove RGB LCD, and then connect the other end to any of the I2C ports on the Grove Shield.
Weather Underground* API key
To optionally fetch the real-time weather information, you need to get an API key from the Weather Underground* website:
http://www.wunderground.com/weather/api
You cannot retrieve weather conditions without obtaining a Weather Underground API key first. You can still run the example, but without the weather data.
Pass your Weather Underground API key to the sample program by modifying the WEATHER_API_KEY key in the config.properties file as follows:
WEATHER_API_KEY="YOURAPIKEY"
Data store server setup
Optionally, you can store the data generated by this sample program in a backend database deployed using Microsoft Azure*, IBM Bluemix*, or AWS*, along with Node.js*, and a Redis* data store.
For information on how to set up your own cloud data server, go to:
https://github.com/intel-iot-devkit/intel-iot-examples-datastore
Configuring the example
To configure the example for the optional data store, change the SERVER
and AUTH_TOKEN
keys in the config.properties
file to the server URL and authentication token that correspond to your own data store server setup. For example:
WEATHER_API_KEY: "YOURAPIKEY" LOCATION: "San_Francisco"
To configure the example for the optional Microsoft Azure* data store, change the SERVER and AUTH_TOKEN keys in the config.properties file as follows:
SERVER: "http://intel-examples.azurewebsites.net/logger/alarm-clock" AUTH_TOKEN: "s3cr3t"
To configure the example for both the weather data and the Microsoft Azure* data store, change the WEATHER_API_KEY, LOCATION, SERVER, and AUTH_TOKEN keys in the config.properties file as follows:
WEATHER_API_KEY: "YOURAPIKEY" LOCATION: "San_Francisco" SERVER: "http://intel-examples.azurewebsites.net/logger/alarm-clock" AUTH_TOKEN: "s3cr3t"
Preparing the Intel® Edison board before running the project
In order for the sample to run you will need to copy some files to the Intel® Edison board. This can be done using SCP through SSH.
Two sorts of files need to be copied from the sample repository:
- Jar files- external libraries in the project need to be copied to "/usr/lib/java"
- web files- files within site_contents folder need to be copied to "/var/AlarmClock"
Running the program using Intel® System Studio IoT Edition
When you're ready to run the example, make sure you have saved all the files.
Click the Run icon on the toolbar of Intel® System Studio IoT Edition. This runs the code on the Intel Edison board.
You will see output similar to the following when the program is running.
Setting the alarm
The alarm is set using a single-page web interface served directly from the Intel® Edison board while the sample program is running.
The web server runs on port 8080, so if the Intel® Edison board is connected to Wi-Fi* on 192.168.1.13, the address to browse to if you are on the same network is http://192.168.1.13:8080.
Determining the IP address of Intel Edison board
You can determine what IP address Intel® Edison board is connected to by running the following command:
ip addr show | grep wlan
You will see output similar to the following:
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0
The IP address is shown next to inet. In the example above, the IP address is 192.168.1.13.
IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments.