Top Banner
Full Stack Meat Project ‘GrillLog’ Kevin Kazmierczak
44

Full Stack Meat Project with Arduino Node AWS Mobile

Jan 10, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Full Stack Meat Project with Arduino Node AWS Mobile

Full Stack Meat Project‘GrillLog’

Kevin Kazmierczak

Page 2: Full Stack Meat Project with Arduino Node AWS Mobile

What are we talking about?

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

Page 3: Full Stack Meat Project with Arduino Node AWS Mobile

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...

Page 5: Full Stack Meat Project with Arduino Node AWS Mobile

Demo

Page 6: Full Stack Meat Project with Arduino Node AWS Mobile
Page 7: Full Stack Meat Project with Arduino Node AWS Mobile
Page 9: Full Stack Meat Project with Arduino Node AWS Mobile

Overview

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

Page 10: Full Stack Meat Project with Arduino Node AWS Mobile

Warning

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

Page 11: Full Stack Meat Project with Arduino Node AWS Mobile

Architecture Overview

Page 12: Full Stack Meat Project with Arduino Node AWS Mobile

Arduino Basics

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

Page 13: Full Stack Meat Project with Arduino Node AWS Mobile

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?

Page 14: Full Stack Meat Project with Arduino Node AWS Mobile

Fritzing Circuit Diagram

Learn more about Fritzing

Page 15: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 16: Full Stack Meat Project with Arduino Node AWS Mobile
Page 17: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 18: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 19: Full Stack Meat Project with Arduino Node AWS Mobile

AWS IoT

Page 20: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 21: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 22: Full Stack Meat Project with Arduino Node AWS Mobile

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)

Page 23: Full Stack Meat Project with Arduino Node AWS Mobile

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"); }

Page 24: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 25: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 26: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 27: Full Stack Meat Project with Arduino Node AWS Mobile

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”

Page 28: Full Stack Meat Project with Arduino Node AWS Mobile

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!

Page 29: Full Stack Meat Project with Arduino Node AWS Mobile

GrillLog Implementation

● Contains 3 tables○ DeviceStatus

■ Current status information per device○ TempLogs

■ Raw temp data from device○ CookLogs

■ Archived cook data

Page 30: Full Stack Meat Project with Arduino Node AWS Mobile

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.

Page 31: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 32: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 33: Full Stack Meat Project with Arduino Node AWS Mobile

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.

Page 34: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 35: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 36: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 37: Full Stack Meat Project with Arduino Node AWS Mobile

Alexa Skill Configuration

UtterancesIntents

Page 38: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 39: Full Stack Meat Project with Arduino Node AWS Mobile

Logging

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

Page 40: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 41: Full Stack Meat Project with Arduino Node AWS Mobile

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

Page 42: Full Stack Meat Project with Arduino Node AWS Mobile

Android Application

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

Page 43: Full Stack Meat Project with Arduino Node AWS Mobile

Future Plans

● PID Controller for fan controlled temperature control

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

Page 44: Full Stack Meat Project with Arduino Node AWS Mobile

Questions