Implementations of the Alarm Robot System
System built in the Cloud
The whole system is built on Amazon EC2 cloud platform. An instance is lauched under Amazon Linux AMI environment. To start with, basic dependent packages will be installed on the instance, such as python, pip, requests, boto3, flask. Then a server is developed under Flask web application framework. There are several responses for the HTTP requests are defined, such as a request to retrieve music in the database according to weather information and the selected singer. The weather information is the response from the OpenWeatherMap weather API. A request from user to set the alarm time and their preferred singer via the website. A request to play music according to the url retrieved from the database and a request from Raspberry pi to get the alarm time. A request from Raspberry pi to get the weather and music information.
Real-Time Weather Information
OpenWeatherMap is a weather api providing users with flexibility of watching for current temperature and weather conditions in your city or any other location on the interactive global map. We choose to access the weather information according to the zipcode of the area. A HTTP GET request containing the zip code of Ithaca is sent to the weather api. The response of the weather information containing the temperature, humidity, weather condition etc is returned in JSON format. We extract the values of two keys in the response, the temperature and weather conditon. To narrow the size of the database, the weather condition is classified into three catogories, Clouds, Clear and NG. NG is the shortcut for NotGood, which represents a broad range of weather conditions including rainy, snowy, windy and so on.The selected weather information is stored in the query preparing for the retrievel of music information in the database.
.
Relational Database in the Cloud
The relational database containing weather and music information is built on Amazon DynamoDB, which is a key-value and document database that delivers single-digit millisecond performance at any scale. Each entry in the relational table has three attributes, weather, singer and info. The weather attribute serves as the partition key and the singer attribute serves as the sort key. The info attribute contains the title of the music and the YOUTUBE url of the music. To select music according to the weather, we define a temperature range [-2,4 ] corresponding to [-20,40] degree centigrade. Taken the three weather conditions in to consideration, there are 21 combinations of weather conditions in granularity. Each combination should relate to a song of specific style to balance the mood of the user in every morning. For example, when the weather condition is NG and it's in the temperature range [-2,-1], a pop rock music such as Shake it Off by Taylor Swift should be played to stimulate the secretion of epinephrine of user, thus achieving the goal of refreshing ! Also, as we offer two singers Taylor Swift and Linkin Park for user to select on the website, there should be 42 entries in the relational table. The music in each entry is well selected based on Psychology lol.
Official Website hosted in the Cloud
The official alarm robot website is designed and hosted on Amazon EC2. Here is the ip address of it. When user open search for the ip address, EC2 will render template of the designed website in response. Before bedtime, users can select their favorite singer(though there are only two options...we will try to build a larger database in the future), set their alarm date including year, month, date(wake up the sleeping beauty a thousand years later...), set their alarm time. After finishing all the settings, users can click the set your robot button to send a HTTP POST request to EC2 to store the information, which will be a component in the query.
Raspberry pi as a Client
As the Alarm robot system is built in the cloud platform, the system is rather portable and flexible. In this project, Raspberry pi will serve as the client and utilize the system to realize several fancy alarming functionabilities with piTFT and servos. As a client, Raspberry pi will send HTTP request to EC2 to get the information of alarm time, weather information, music information, which will be displayed on the piTFT in real-time. The alarm time will be compared to the present time, which is obtained from the real time clock, to calculate the sleeping time of the raspberry time. After the Raspberry pi is waken at the alarm time, two_wheels program will be executed to motivate the servo to move randomly and avoid obstacles with IR sensor. Music will be downloaded from YOUTUBE and played on the OMXPlayer.