Transcript

Full Stack Meat Project‘GrillLog’

Kevin Kazmierczak

What are we talking about?

Creating a custom built dual probe BBQ thermometer instead of buying one

Motivation

● Learn Arduino and basic electronics● Be able to see grill temperatures on my devices● Get notified when it was ready● Learn AWS● I thought it’d be similar in cost...

Demo

Overview

● Arduino● AWS IoT● Lambda● DynamoDB● API Gateway● SNS● Alexa● iOS● Web● Android

Warning

I am not an expert in any of this. Please feel free to add additional context or information as needed.

Architecture Overview

Arduino Basics

● 14 Digital I/O Pins ( 6 PWM )● 6 Analog● 5V● Embedded code written in C/C++ as a ‘Sketch’

Arduino Yun

● Device details○ Built in wifi○ Two processors, traditional ATmega and AR9331 (Linux)○ Linux processor handles all the more CPU intensive tasks ( wifi / data processing )○ ATmega handles reading/writing outputs

● How does it compare to others?● Could you replace this with a RPi?

Fritzing Circuit Diagram

Learn more about Fritzing

GrillLog Implementation

● Every 10 seconds the device reads two analog inputs

● Using a Steinhart–Hart equation, it converts the analog resistance to temperature

● Equation coefficients calibrated by taking 3 different temperatures and plugged into an online calculator

● Current readings are dumped to Serial and the LCD display

AWS Fine Print

● Sign up for a free tier trial account● One year of free tier account services● Some of the core services have very generous free limits even

without a trial account● Pay for what you use● Security

○ Ensure that there are roles setup that have access to execute the pieces of the

different services

AWS IoT

● Allows device to communicate over MQTT with encrypted traffic● MQTT - Lightweight messaging protocol, think JMS or Pub/Sub ● Each device gets a signed certificate to use with messaging● Devices can have shadows for offline sync● Compatible devices - Anything that can do secure MQTT● Use command line mosquitto to simulate device messaging

AWS IoT

AWS IoT Rules

● Rules can filter messages into different channels● SQL query like syntax to set them up● Use built in actions● Lambda is most flexible action

GrillLog Implementation

● Yun has certificates installed● Yun constructs JSON document of

temps● Yun posts message on ‘templogs’ topic● AWS has a rule that all incoming

‘templog’ messages are forwarded to a lambda function

● Tweaked AWS config to solve memory issues

AWS Lambda

● Runs code in response to events● Pay for what you consume● Develop in Javascript/Java/Python● No servers to manage or scale● Core service used to integrate across AWS● Pricing

○ First 1 million requests per month are free○ $0.20 per 1 million requests thereafter ($0.0000002 per request)

Lamba Basics

● Can start from one of their many templates○ Language specific○ Voice templates○ Microservices○ Hello world

● Export a ‘handler’ that takes and event, context, callback● Do whatever

exports.handler = function(event, context, callback) { console.log("value1 = " + event.key1); console.log("value2 = " + event.key2); callback(null, "some success message"); // or // callback("some error type"); }

GrillLog Implementation

● Three lambda functions○ Handle incoming IoT messages○ Handle web requests○ Handle voice requests

● All three lambdas just forward into a custom controller/service layer written in Node.js

Custom Service Layer

● AWS supports Node 4.3 (finally!!!)○ ES2016 (ES6) features

■ Promises/arrow functions/etc - check for support before using

● Controller processes input and utilizes services needed○ Could swap out service implementations later if needed

● Promise based - AWS sdk methods can return a promise● Easy to test via command line locally● Use any packages you need via npm● Service layer gets packaged with lambda

GrillLog Implementation

● Utilizes the aws-sdk package● Deployed via shell script

○ Creates a zip file of required files○ Calls AWS specific CLI tooling○ Cleans up

● Uploads a zip per each lambda endpoint

AWS DynamoDB

● NoSQL database similar to MongoDB○ Schema-less

● Event driven hooks● Easy to save data, not as easy to query● Integration with other AWS services with streams/triggers● Pricing

○ 25 GB in free tier, pay per usage

○ “For a little less than $0.25/day ($7.50/month), you could support an application

that performs 1 million writes and reads per day”

DynamoDB Basics

● Each table has a primary key (hash key) - Most unique● Optional sort key - What will I most likely sort on?● Get data out via either a ‘scan’ or ‘query’

○ ‘query’ requires primary key then you add filter criteria

● Indexes are required to speed up queries● Sorting is tricky● No date datatype, have to use a timestamp number● Save whatever!

GrillLog Implementation

● Contains 3 tables○ DeviceStatus

■ Current status information per device○ TempLogs

■ Raw temp data from device○ CookLogs

■ Archived cook data

AWS SNS - Simple Notification Service

● Pub-sub messaging● Deliver across multiple protocols

○ iOS/Android○ Email○ SMS

● Hooks into other services● Pricing

○ Your first 1 million push requests are free○ $0.50 per 1 million Amazon SNS requests thereafter.

SNS Basics

● Create platform application○ Need certificates to handle push integration with Apple/Google

● Devices can register to application with token● Messages can be sent to the endpoints registered● Raw or JSON● Can tie multiple endpoints together via subscriptions

○ Topic could post to email and push together

● Push messages via AWS dashboard

GrillLog Implementation

● Devices are manually registered with device token on dashboard

● Application endpoint created with Apple push certificates from iTunes provisioning portal

● Custom services push JSON formatted messages for Apple devices

AWS API Gateway

● Deploy a customized API● Define the resources that can be called● SDK generation● Authentication - keys, IAM, CORS● Pricing

○ Free tier includes one million API calls per month for up to 12 months○ $3.50 per million API calls received, plus the cost of data transfer out, in gigabytes.

API Gateway Basics

● You can create an API endpoint from the lambda ‘API endpoints’ tab● Create resources as endpoints like

○ /status or /logs

● Add methods to those resources○ GET/POST/PUT

● Point those endpoints to a lambda or proxy● Configure the mappings - How will data pass through● Customize as needed● Create multiple ‘stages’ that you can deploy to

GrillLog Implementation

● Exposes REST endpoints○ status/logs/startgrill/startcook/endgrill

● CORS enabled on status/logs for web● Mobile clients handle state movement● Entire request information is

forwarded to a lambda● Lambda determines what the URL

should do and call proper controller method in custom services

Alexa Integration

● Registered skill on amazon developer site● Forward to lambda or custom deployed services (HTTPS)● Register intents ( voice input formats )● Deploy to app store - Requires approval

○ They are VERY strict that you follow the guidelines○ You could get a free t-shirt

● Test on developer site○ Lets you hear responses and see source JSON

● Detailed skill creation walkthrough

Alexa Skill Configuration

UtterancesIntents

GrillLog Implementation

● Registered skill forwarding to lambda● Simple ‘what’s the status’ intent● Calls into custom services to grab

current status● Converts response into a text string

passed back to voice services

Logging

● Configure services to write CloudWatch logs● Add alerts if needed

iOS Application

● Apple developer account - $99○ Be able to deploy to devices and provision

● Configured app in iTunes connect● Generate APNS certs imported to SNS● Written in Swift● Polls for temp status every 10 sec● Regenerates chart every 30 sec● Uses ‘Charts’ project for charting● Sends push notifications

○ Warm temperature threshold○ Food temperature

● Background fetch to detect offline situations

Web Application

● Deployed on http://grilllog.kevinkaz.com ● Written in ES2016 transpiled in webpack● Uses D3 to handle charting● Uses a fetch polyfill● Styling done in Less

Android Application

● Written by coworker, Chris Scott● Mortar and Flow for view lifecycles● Dagger for dependency injection● RxJava and Retrofit for service integration

Future Plans

● PID Controller for fan controlled temperature control

● Apple Watch Complication● Waterproof case● More notifications● Review past cooks● Archive condensed logs

Questions


Recommended