My son Adhiyan had a bout of common cold last month and we had to spend many sleepless nights to look after him. We had to make sure that he is taking the feeds well and is well hydrated. Having slept very little, it was getting difficult for us to keep track of baby data like pee count, poop count, etc. Then, we felt the need for a system for tracking details of the baby easily. There are tons of applications available for Android and iOS. However, we have realized over time that taking the phone out, opening the app and feeding the data was not an easy experience either (especially in the midnight). Then, I recollected the hack built by Ted around Amazon's WiFi button to track baby data. Physical buttons seem to be much convenient for tracking baby data. Amazon's buttons are not yet available in India. Hence, I decided to build something similar on my own and in the process wanted to explore the recently announced AWS IoT service. I also wanted to use the opportunity to explore couple of other technologies: 1. Physical web from Google 2. ServiceWorker Push. Finally, after couple of weekends, here is my hack to track baby data using Raspberry Pi and AWS IoT. Source code of the whole setup is available here.
Raspberry Pi Trackpad
I have built a simple trackpad with a breadboard, few LEDs and five pushbuttons - four buttons for counting baby data (pee, poop, feeds, sneeze) and another one for pinging a remote device. The ping button is meant to send an emergency notification to a remote device. I have built this for my wife to be able to reach me easily. The trackpad connects to Raspberry Pi 2 via GPIO pins. While connecting the trackpad to RPi GPIO pins, I have learnt that the ordering of pins in RPi is quite crazy. The physical ordering and chipset pin numbering are entirely different. I wanted to build a node app for reading the button inputs and pass them along to AWS IoT infrastructure. However, I couldn't find any reliable GPIO node module for reading / writing to GPIO pins. Hence, I wrote a python module for reading button data and relaying them to the node app for interfacing with Amazon cloud.
The trackpad becomes a 'thing' in the context of AWS IoT. I am really happy with the way that the trackpad had turned out. The connections on the breadboard are quite neat and flat. Look how neatly the ground wires have been arranged on the board.
AWS IoT
AWS IoT is a managed cloud service that lets connected devices easily interact with cloud applications and other devices. The service supports HTTP and MQTT, a lightweight communication protocol specially designed for devices with poor connectivity and low CPU power / memory footprint. The communication between the thing (device) and the cloud is encrypted and hence secure. Any IoT application built using AWS IoT will have to do three tasks (via IoT API): 1. Register 'thing' with the registry. Get necessary certificates to authenticate and communicate. 2. Configure a bunch of rules and actions to route messages / data from the device to various cloud services. 3. Process and act upon device data. Know more about AWS IoT here. Check out the visual tutorial from the AWS console.
For the hack, I have configured rules to persist baby data in dynamodb and route the same data to AWS lambda. When a button is pressed on the trackpad, the node app running in RPi will publish a message (over MQTT) to AWS IoT. Then, the rules will forward the data to dynamodb and lambda. On top of DynamoDB, I intended to use Amazon Quicksight for visualizing the data and finding out patterns from them. Amazon Quicksights is available only in preview mode. Hence, I have chosen to publish the data to Google docs also and visualize the data there. I have employed a lambda function for the same. The lambda function will route all data to Google sheets and persist the data there. Then, I have built visualizations on top of Google sheets.
Reading the baby data using "The Physical web"
Over time as we use the trackpad, the data will get captured in Google docs as well as in the dynamodb. One can go to the Google docs directly to visualize the data. But, I need to remember the URL every time to check out the data. I wanted to make this process easier with the help of the "physical web" project from Google. With the tagline "Walk up and use anything", the project uses open Eddystone-URL Bluetooth beacon format for discovering things in an IoT environment and read data from them. I have enhanced the node application on the trackpad to publish an eddystone URL over BLE 4.0. Now, to read the data for any given day, I just need to use the "physical web" app on mobile. The app will read data from the published eddystone URL and show the data in the app. (No need to remember the URL). The real power of the physical web can be seen only when there are multiple things in your connected environment. You can just take your smartphone near the device to read data from it.
The Ping button
I have built the ping button for my wife to be able to reach me easily. Pressing the button will send a push notification to my mobile, desktop, etc. I have added this functionality to https://adhiyan.in (a progressive web app) with basic authentication support. The push notification has been implemented using the awesome new kid on the web platform "Service Worker". When the button is pressed, the node app running on the trackpad will publish a message to AWS IoT. Lambda function on the cloud will process the message and forward the same to "Google cloud messaging" (GCM) infrastructure. GCM will then push the message to the browser which has service worker deployed. More details about push notifications on the open web can be found here. My service worker recipe can be found here. Source code of adhiyan.in site is available here.
Overall, it was a very good learning experience. The final product turned to be a mashup of many technologies and eventually being very effective and useful.
-- Varun
No comments:
Post a Comment