Scripting Things Pittsburgh Perl Workshop 2011 Carnegie Mellon University Hans Scharler www.ioBridge.com @scharler
Objectives Introduce the “Internet of Things” Learn how to Innovate Answer: Why Perl? Interface the Real-world Learn how to start a project Plant some ideas Answer Questions
The Internet of Things Sensors Controllers People Buildings Connectivity Applications Source: The Things People Things
The Internet of Things Is server monitoring too boring for the Internet of Things?  NO…  Write a simple script to monitor CPU and RAM utilization and push that data out to a web service to measure server uptime and performance IoT is only going to work in small steps. It starts with remote server monitoring and ends with SkyNet.
Innovation Source: everythingisaremix.info
Innovation Example Temperature Sensing Temperature Sensing Humidity Sensing Humidity Sensing + Twitter Tweeting Humidor
The Solution Perl?
The Benefits of Perl Parsing String Operations REGEX Native Serial Hardware Abstraction Connecting APIs CPAN
The Opportunity “ Imagine if we attach Perl to the emerging Internet of Things” --Hans Scharler “ Industry Leading Expert” Source: Hans Scharler
Perl’s Keys to Success Examples written in Perl CPAN module for Arduino® / ioBridge® Projects that use Perl to connect things
Interface to the Real World Digital I/O Analog Serial (via)  Network Protocols
Digital I/O Digital   = Discrete States (On/Off) I   = Input O   = Output Use Digital I/O to check if something is On / Off (input) or to turn something On / Off (output)
Digital Output Device generates some voltage to represent the “On” state – typically 5v Device generates some voltage to represent the “Off” state – typically 0v
Digital Output If something that you are hacking has a button or switch, you can just replace it with a Digital Output / Relay to operate that device (most of the time) “ 1100110001101” (bark)
Digital Input Read in voltage that represents the “On” state – typically 5v Read in voltage that represents the “Off” state – typically 0v
Digital Input Use Digital Inputs to see if something is opened / closed, up / down, or on / off Down Open On
Analog Input Varying voltages – typically from 0 to 5v Higher voltages indicate more of something Lower voltages indicate less of something Used for sensors Source: physicscentral.com
Analog Input: Temperature Source: physicscentral.com Voltage Time ->
Analog Input for Sensors Examples of Analog Input: Temperature Humidity Pressure Light Levels Distance  / Range Volume Source: physicscentral.com
Serial Serial is a way of passing data one piece at a time between devices A little more complicated, but Serial has universal concepts: Databits  –  typically 8 Baud Rate / Speed  –  typically 9,600 or 19,200 Parity  –  typically “none” Stop Bits  –  typically 1
Serial Even more Serial Concepts… RS-232 Short distance communication Higher voltages – old serial ports on computers and modems UART Short distance commutations 0 to 5v Used with microcontrollers such as Arduino® RS-485 Long distance serial Used more by industrial control systems
Serial-over-USB Converts USB to UART Serial
Device::SerialPort ls -la /dev/tty* use Device::SerialPort; my $port = Device::SerialPort->new("/dev/tty.usbserial"); $port->baudrate(19200); $port->databits(8); $port->parity("none"); $port->stopbits(1); Find your serial device: Perl Setup: Settings must match on both sides
Device::SerialPort my $char = $port->lookfor(); print “$char \n”; $port->write(“Hello World"); Read Serial Data: Send Serial Data: See Also: Win32::SerialPort Firmata for Arduino: http://firmata.org/wiki/Download https://github.com/amimoto/perl-firmata
Network Protocols Abstraction of physical interface over network protocols Serial-over-Ethernet HTTP GET  to get data from a Digital or Analog Input HTTP POST / PUT  to control a Digital Output API to Device - “ioBridge”
Serial over Network Serial Serial Ethernet Ethernet Now you can go a long distance over UART serial
“ ioBridge” ioBridge IO-204 Ethernet Module Relay Thermostat Temperature Sensor HTTP POST “ turn on thermostat” HTTP GET “ temperature”
How to Start Start small Duplicate someone else's well documented project  (check Instructables.com or Google) Break every project down to a list of basic concepts  (Digital I/O, Analog, Serial, Network Protocols) Transform the basic design  (make a change) Combine the design with other ideas  (add Twitter) Finish big
What We Do Projects!
Internet Pet Feeders 2008  2009  2010
Projects turned Products
Platform Technologies Optimized TCP/IP Stack Portable Client Real-time Streaming, Web Sockets, Comet Application Design Platform API Abstraction Visualizations
Projects turned Products
Control Heating/Cooling Based on Current Position and Weather Track Your Location With Google Latitude
iPhone Controlled Beer Cannon Mini Fridge Beer Cannon by Ryan Rusnak Over 1 million YouTube Views Demo’d Live on TV In the June 2011 issue of Popular Science Featured on JUNKies -- TV Show on Discovery Science
Learn more… My blog -  http://iamshadowlord.com “ Thermd” Perl Module -  http://www.klein.com/thermd Arduino -  http://www.arduino.cc ioBridge –  http://www.iobridge.com Instructables –  http://www.instructables.com
Q&A Hans Scharler [email_address] www.ioBridge.com

Scripting Things - Creating the Internet of Things with Perl

  • 1.
    Scripting Things PittsburghPerl Workshop 2011 Carnegie Mellon University Hans Scharler www.ioBridge.com @scharler
  • 2.
    Objectives Introduce the“Internet of Things” Learn how to Innovate Answer: Why Perl? Interface the Real-world Learn how to start a project Plant some ideas Answer Questions
  • 3.
    The Internet ofThings Sensors Controllers People Buildings Connectivity Applications Source: The Things People Things
  • 4.
    The Internet ofThings Is server monitoring too boring for the Internet of Things? NO… Write a simple script to monitor CPU and RAM utilization and push that data out to a web service to measure server uptime and performance IoT is only going to work in small steps. It starts with remote server monitoring and ends with SkyNet.
  • 5.
  • 6.
    Innovation Example TemperatureSensing Temperature Sensing Humidity Sensing Humidity Sensing + Twitter Tweeting Humidor
  • 7.
  • 8.
    The Benefits ofPerl Parsing String Operations REGEX Native Serial Hardware Abstraction Connecting APIs CPAN
  • 9.
    The Opportunity “Imagine if we attach Perl to the emerging Internet of Things” --Hans Scharler “ Industry Leading Expert” Source: Hans Scharler
  • 10.
    Perl’s Keys toSuccess Examples written in Perl CPAN module for Arduino® / ioBridge® Projects that use Perl to connect things
  • 11.
    Interface to theReal World Digital I/O Analog Serial (via) Network Protocols
  • 12.
    Digital I/O Digital = Discrete States (On/Off) I = Input O = Output Use Digital I/O to check if something is On / Off (input) or to turn something On / Off (output)
  • 13.
    Digital Output Devicegenerates some voltage to represent the “On” state – typically 5v Device generates some voltage to represent the “Off” state – typically 0v
  • 14.
    Digital Output Ifsomething that you are hacking has a button or switch, you can just replace it with a Digital Output / Relay to operate that device (most of the time) “ 1100110001101” (bark)
  • 15.
    Digital Input Readin voltage that represents the “On” state – typically 5v Read in voltage that represents the “Off” state – typically 0v
  • 16.
    Digital Input UseDigital Inputs to see if something is opened / closed, up / down, or on / off Down Open On
  • 17.
    Analog Input Varyingvoltages – typically from 0 to 5v Higher voltages indicate more of something Lower voltages indicate less of something Used for sensors Source: physicscentral.com
  • 18.
    Analog Input: TemperatureSource: physicscentral.com Voltage Time ->
  • 19.
    Analog Input forSensors Examples of Analog Input: Temperature Humidity Pressure Light Levels Distance / Range Volume Source: physicscentral.com
  • 20.
    Serial Serial isa way of passing data one piece at a time between devices A little more complicated, but Serial has universal concepts: Databits – typically 8 Baud Rate / Speed – typically 9,600 or 19,200 Parity – typically “none” Stop Bits – typically 1
  • 21.
    Serial Even moreSerial Concepts… RS-232 Short distance communication Higher voltages – old serial ports on computers and modems UART Short distance commutations 0 to 5v Used with microcontrollers such as Arduino® RS-485 Long distance serial Used more by industrial control systems
  • 22.
  • 23.
    Device::SerialPort ls -la/dev/tty* use Device::SerialPort; my $port = Device::SerialPort->new("/dev/tty.usbserial"); $port->baudrate(19200); $port->databits(8); $port->parity("none"); $port->stopbits(1); Find your serial device: Perl Setup: Settings must match on both sides
  • 24.
    Device::SerialPort my $char= $port->lookfor(); print “$char \n”; $port->write(“Hello World"); Read Serial Data: Send Serial Data: See Also: Win32::SerialPort Firmata for Arduino: http://firmata.org/wiki/Download https://github.com/amimoto/perl-firmata
  • 25.
    Network Protocols Abstractionof physical interface over network protocols Serial-over-Ethernet HTTP GET to get data from a Digital or Analog Input HTTP POST / PUT to control a Digital Output API to Device - “ioBridge”
  • 26.
    Serial over NetworkSerial Serial Ethernet Ethernet Now you can go a long distance over UART serial
  • 27.
    “ ioBridge” ioBridgeIO-204 Ethernet Module Relay Thermostat Temperature Sensor HTTP POST “ turn on thermostat” HTTP GET “ temperature”
  • 28.
    How to StartStart small Duplicate someone else's well documented project (check Instructables.com or Google) Break every project down to a list of basic concepts (Digital I/O, Analog, Serial, Network Protocols) Transform the basic design (make a change) Combine the design with other ideas (add Twitter) Finish big
  • 29.
    What We DoProjects!
  • 30.
    Internet Pet Feeders2008 2009 2010
  • 31.
  • 32.
    Platform Technologies OptimizedTCP/IP Stack Portable Client Real-time Streaming, Web Sockets, Comet Application Design Platform API Abstraction Visualizations
  • 33.
  • 34.
    Control Heating/Cooling Basedon Current Position and Weather Track Your Location With Google Latitude
  • 35.
    iPhone Controlled BeerCannon Mini Fridge Beer Cannon by Ryan Rusnak Over 1 million YouTube Views Demo’d Live on TV In the June 2011 issue of Popular Science Featured on JUNKies -- TV Show on Discovery Science
  • 36.
    Learn more… Myblog - http://iamshadowlord.com “ Thermd” Perl Module - http://www.klein.com/thermd Arduino - http://www.arduino.cc ioBridge – http://www.iobridge.com Instructables – http://www.instructables.com
  • 37.
    Q&A Hans Scharler[email_address] www.ioBridge.com