Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda

Download Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda

Post on 02-Aug-2015

1.703 views

Category:

Technology

0 download

Embed Size (px)

TRANSCRIPT

<p> 1. Internet Of Things Bologna 2015, June 17 2. Taking pictures!! For Internet Of Things! 3. Raspbery Pi About 30$ Big as a credit card A powerful ARM! GNU/Linux on board More... 4. The Camera module About 30$ around 25 x 20 x 9 mm 5 Megapixels Supports 1080p30, 720p60, VGA90 video More... 5. Grab pictures Enable the camera module via raspi-config Just use it: raspistill -o me.jpg 6. Hey@CorleyCloudhereisyourpicture: pic.2015.cloudconf.it/CorleyCloud/61 pic.twitter.com/LW8jUSPIa7 3:33PM16Jun2015 16JunCorley @CorleyCloud #cloudconf2015#pic CloudConf @_CloudConf_ Follow Read for tweets and reply back with pictures! 7. The tweet process Raspberry read a twitter stream for #cloudconf2015 #pic Raspberry upload the original picture to AWS S3 AWS Lambda resize the image and optimize it for the web AWS Lambda tweet the picture to the final user 8. On Raspberry Pi Golang Powerful available for multiple platforms (x86, ARM, ...) self-contained binaries Much more! 9. Read the Twitter Stream import( tw"github.com/wdalmut/twitterstream/async" ) client:=tw.NewClient( config.ConsumerKey, config.ConsumerSecret, config.AccessToken, config.AccessSecret, ) client.TrackAndServe("cloudconf2015",func(tweet*twitterstream.Tweet){ //Herethelogic! }) github.com/wdalmut/twitterstream/async github.com/darkhelmet/twitterstream 10. Grab pictures using commands! (easy) cmd:=exec.Command( "raspistill",//Commandname "a","www.cloudconf.it#cloudconf2015",//Watermarks "t","500", "vf","hf",//Rotate "w","1024","h","768",//1024x768 "quality","60",//60% "o","/tmp/pic.jpg")//Putin/tmpfolder err:=cmd.Run() You can also take pictures using OS Signals 11. Upload on AWS S3 //Uploadit! err=bucket.Put(path,bytes,"image/jpg",s3.ACL("publicread"),s3.Options{}) Prepare the AWS client AWSAuth:=aws.Auth{ AccessKey:config.Key, SecretKey:config.Secret, } region:=aws.EUWest connection:=s3.New(AWSAuth,region) bucket:=connection.Bucket(BUCKET) https://github.com/wdalmut/raspi-twitter-cloudconf 12. Cross-Compiling (install GO for ARM) Prepare your environment $cd$GOROOT/src $GOOS=linuxGOARCH=arm./make.bashnoclean Compile your source code $GOARM=6GOARCH=armGOOS=linuxgobuild 13. Use a Makefile default:all all:test GOARM=6GOARCH=armGOOS=linuxgobuilda sshpi@$(TARGET)'killallpicme|true' scpstart.shpi@$(TARGET):~ scppicmepi@$(TARGET):~ scpconfig.jsonpi@$(TARGET):~ sshpi@$(TARGET)'./picme/tmp/picme.log2&gt;&amp;1&amp;' test: gotestv./... Compile it locally, copy it into the Raspi and run it on board! TARGET=192.168.1.53make 14. Lambda receive the S3 upload event ... now we have to tweet the picture 15. AWS Lambda works with Javascript But I prefer Coffeescript 16. Coffeescript and Lambda /*Preparethe"twitter"client...*/ exports.handler=(event,context)&gt;/** context.donenull,"" (err)&gt; context.doneerr,"Unabletotweet!" ) Just code with your event! 17. S3 upload event! { "Records":[ { "s3":{ "bucket":{ "name":"sourcebucket", "ownerIdentity":{ "principalId":"XXXXXXXXXXXXXXXXX" }, "arn":"arn:aws:s3:::example.walterdalmut.com" }, "object":{ "key":"walterdalmut/1924762.jpg", "size":1024, "eTag":"11111111111111111111111111111111" } } } ] } Please consider that this is not a real S3 event (just a part of it...) 18. Test your Lambdas handler=require'../src/lambda' describe"Lambdacallback",&gt; beforeEach&gt; @context={} @context.done=()&gt; @event={ "Records":[ {/*...*/} ] } it"shouldexposethelambdahandler",&gt; spyOn(handler,"handler").and.returnValuenull handler.handler(@event,@context) expect(handler.handler).toHaveBeenCalled() 19. A look into the Lambda function https://github.com/wdalmut/lambda-twitter-cloudconf 20. Deploy on AWS Lambda Simple prepare a ZIP artifact gruntdist 21. tweetit!#cloudconf2015#pic 22. Thanks for listening </p>