exploring the internet of things using ruby

58
Exploring the Internet of Things with Ruby Lone Star Ruby Conf 2012

Upload: mike-hagedorn

Post on 08-May-2015

1.301 views

Category:

Technology


0 download

DESCRIPTION

talk on the internet of things and how ruby can be used. Given at lsrc12

TRANSCRIPT

Page 1: Exploring the Internet of Things Using Ruby

Exploring the Internet of Things

with RubyLone Star Ruby Conf 2012

Page 2: Exploring the Internet of Things Using Ruby
Page 3: Exploring the Internet of Things Using Ruby

Man Versus Wild…

Page 4: Exploring the Internet of Things Using Ruby

The Great Adventure

Page 5: Exploring the Internet of Things Using Ruby

The Oh No Moment

(aka – I am going to have to drink my urine)

Page 6: Exploring the Internet of Things Using Ruby

Whoami

Mike Hagedorn@mwhagedorn

github.com/mwhagedorn

Page 7: Exploring the Internet of Things Using Ruby

Agenda

Internet Of Things in General Ruby and USB The IOT Printer The IOT Display

Page 8: Exploring the Internet of Things Using Ruby

Agenda

Internet Of Things in General Ruby and USB The IOT Printer The IOT Display

Page 9: Exploring the Internet of Things Using Ruby

Internet of Things?

“Listen to your world, talk to the Internet”

http://supermechanical.com/

Objects-> Internet -> Servers

Page 10: Exploring the Internet of Things Using Ruby

Things Talk back

Page 11: Exploring the Internet of Things Using Ruby

@MarsCuriosity

Page 12: Exploring the Internet of Things Using Ruby

Botanicalls

Page 13: Exploring the Internet of Things Using Ruby

IOT Devices

Arduino Rasberry Pi Twine

Page 14: Exploring the Internet of Things Using Ruby

Agenda

Internet Of Things in General Ruby and USB The IOT Printer The IOT Display

Page 15: Exploring the Internet of Things Using Ruby

The USB Lamp Project

http://www.thekua.com

Page 16: Exploring the Internet of Things Using Ruby

The USB Lamp Project

libusb gem open a context browse for your

device open the device send message close device

Easy!

NOT

Page 17: Exploring the Internet of Things Using Ruby

The USB Lamp Project

Lots of Questions How do you send messages? What is the form of the messages?

Page 18: Exploring the Internet of Things Using Ruby

Use The Source Luke…

void USBLamp::init() { char data1[8] = { 0x1f, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x03 }; send(data1, sizeof(data1));

char data2[8] = { 0x00, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x04 }; send(data2, sizeof(data2));

char data3[8] = { 0x00, 0x02, 0x00, 0x2e, 0x00, 0x00, 0x2b, 0x05 }; send(data3, sizeof(data3));}

Page 19: Exploring the Internet of Things Using Ruby

Use The Source Luke…

void USBLamp::send(char *bytes, int size) { … CALL(usb_control_msg(…)) …}

Page 20: Exploring the Internet of Things Using Ruby

Array#pack & String#unpack pack

Array of numbers to a binary string[97,98,99].pack("c*")=> "abc“

unpack Binary string to array

"abc".unpack("c*")=> [97,98,99]

Page 21: Exploring the Internet of Things Using Ruby

Demo

Page 22: Exploring the Internet of Things Using Ruby

Agenda

Internet Of Things in General Ruby and USB The IOT Printer The IOT Display

Page 23: Exploring the Internet of Things Using Ruby

The IOT printer

Page 24: Exploring the Internet of Things Using Ruby

The IOT printer

Page 25: Exploring the Internet of Things Using Ruby

Arduino

Page 26: Exploring the Internet of Things Using Ruby

Ethernet Shield

Page 27: Exploring the Internet of Things Using Ruby

Arduino IDE

Page 28: Exploring the Internet of Things Using Ruby

To Rad or Not To Rad

Page 29: Exploring the Internet of Things Using Ruby

To Rad or Not To Rad

Page 30: Exploring the Internet of Things Using Ruby

Tools You Can Trust

Page 31: Exploring the Internet of Things Using Ruby

Use TextMate!

Page 32: Exploring the Internet of Things Using Ruby

Use Terminal!

You can monitor the serial port via Terminal

> ls /dev/tty.*> screen <dev> <baud-rate> End with cntrl-A, cntrl-\

Page 33: Exploring the Internet of Things Using Ruby

IOT-Assistantgithub.com/newsinternational/iot-assistant

Page 34: Exploring the Internet of Things Using Ruby

Architecture

OAuthCalendars

Tweets

Page 35: Exploring the Internet of Things Using Ruby

Suiting It To Me

Calendar Tasks News Twitter

(Oauth)

Page 36: Exploring the Internet of Things Using Ruby

Omnifocus Challenges

How can I get my tasks exported? How can I get them up to the server?

Page 37: Exploring the Internet of Things Using Ruby

Applescript

Page 38: Exploring the Internet of Things Using Ruby

Applescript Dictionary

Page 39: Exploring the Internet of Things Using Ruby

Exporting Omnifocus tasks

#!/usr/local/bin/macrubyframework 'Foundation'framework 'ScriptingBridge'

OFOC = "com.omnigroup.Omnifocus” @of = SBApplication.applicationWithBundleIdentifier(OFOC) load_bridge_support_file 'Omnifocus.bridgesupport' @doc = @of.defaultDocument tasks = [] @doc.flattenedTasks.get.each do |task| tasks << task end

Page 40: Exploring the Internet of Things Using Ruby

How can the server get this? Omnifocus tried to solve this Have to expose your desktop on

internet More work than most people want to

do

Page 41: Exploring the Internet of Things Using Ruby

Use HP Object Storage!

Page 42: Exploring the Internet of Things Using Ruby

HpObjectStore Helper

Uses Fog

def tasks_dir @connection.directories.get("omnifocus")end

def update_tasks_file(content) tasks_dir.files.create(:key => "tasks.json", :body => content)end

Page 43: Exploring the Internet of Things Using Ruby

Update Cloud Bucket

Run a chron job from my desktop server

All my omnifocus installs are already synced

Server gets a current task list

Page 44: Exploring the Internet of Things Using Ruby

Outlook

Need my calendar Don’t want to deal with corp security Use the same omnifocus technique

Page 45: Exploring the Internet of Things Using Ruby

The Printout

Page 46: Exploring the Internet of Things Using Ruby

The Arduino Code

Page 47: Exploring the Internet of Things Using Ruby

Demo

Page 48: Exploring the Internet of Things Using Ruby

Agenda

Internet Of Things in General Ruby and USB Ruby and RFID The IOT Printer The IOT Display

Page 49: Exploring the Internet of Things Using Ruby

The IOT Display

http://bit.ly/vlMMvr

Original Inspiration:

Page 50: Exploring the Internet of Things Using Ruby

Arduino

Page 51: Exploring the Internet of Things Using Ruby

32X8 Led Panel

http://bit.ly/wyuE5V

Page 52: Exploring the Internet of Things Using Ruby

WiFly

Page 53: Exploring the Internet of Things Using Ruby

Fritzing Sketch

Page 54: Exploring the Internet of Things Using Ruby

Using IOT-A

Already had an infrastructure Already had a datasource Format didn’t make sense for LED

Display

Page 55: Exploring the Internet of Things Using Ruby

User-Agent

Use two different User-Agent header values

User-Agent:IOTDisplay User-Agent:IOTPrinter JSON representation for display

Page 56: Exploring the Internet of Things Using Ruby

Memory and the Sad Panda

Standard JSON parser took up too much memory

Char strings storage Had to give up a key feature

Page 57: Exploring the Internet of Things Using Ruby

Demo

Page 58: Exploring the Internet of Things Using Ruby

HP Cloud For Free!

https://www.hpcloud.com/free-trial

@mwhagedorn

Thanks!

https://github.com/mwhagedorn/IOTDisplay.git

https://github.com/mwhagedorn/iot_printer_remote.githttps://github.com/mwhagedorn/iot-assistant.git

https://github.com/mwhagedorn/thingspeak.git