65
Raspberry Pi A La CFML Tasty, tasty CFML on a Pi Brad Wood @bdw429s pi.bradwood.com

Raspberry pi a la cfml

Embed Size (px)

Citation preview

Page 1: Raspberry pi a la cfml

Raspberry Pi A La CFMLTasty, tasty CFML on a Pi

Brad Wood@bdw429s

pi.bradwood.com

Page 2: Raspberry pi a la cfml

● ColdFusion Architect (12 years) ● Geek ● Android Lover● Blogger (codersrevolution.com)● ColdBox Platform Evangelist● Musician● Shade-Tree Mechanic● Husband (12 years)● Dad (3 beautiful girls)

The Weird Dude With The Mic

Page 3: Raspberry pi a la cfml

What Is It?

Page 4: Raspberry pi a la cfml

What Is It?

Page 5: Raspberry pi a la cfml

Arduino

Haven’t I seen this before?

Raspberry Pi

Page 6: Raspberry pi a la cfml

● $35 $25● 1 GB Ram● 900 MHz Quadcore ARM CPU (overclockable)● HDMI● 4x USB● Micro USB power● Audio Jack● Camera Interface● Network● GPIO● Micro SD

What Is It?

Page 7: Raspberry pi a la cfml

Fits in the palm of your hand.

What Is It?

Page 8: Raspberry pi a la cfml

Well, almost...

What Is It?

Page 9: Raspberry pi a la cfml

● 2A power adapter● USB Keyboard● USB Mouse● MicroSD card● An operating system● HDMI display● Wifi or Ethernet hookup● LED-adorned hat (optional)

You also want/need…

Page 10: Raspberry pi a la cfml

It Does Cool Stuff!

Page 11: Raspberry pi a la cfml

Like What?

Run Linux

Page 12: Raspberry pi a la cfml

Like What?

Use Openoffice

Page 13: Raspberry pi a la cfml

Make a cool case

Like What?

Page 14: Raspberry pi a la cfml

Play Minecraft

Like What?

Page 15: Raspberry pi a la cfml

Program in Python (Scratch)

Like What?

Page 16: Raspberry pi a la cfml

Media Center

Like What?

Page 17: Raspberry pi a la cfml

Robot

Like What?

Page 18: Raspberry pi a la cfml

Make a 4-RPI Cluster

Like What?

Page 19: Raspberry pi a la cfml

Make a 40-RPI Cluster

Like What?

Page 20: Raspberry pi a la cfml

Make a 64-RPI Cluster

Like What?

Page 21: Raspberry pi a la cfml

And you can run CFML

Like What?

Page 22: Raspberry pi a la cfml

● NOOBS● Raspbian Linux (Debian)

○ Gnome Desktop (Pi Store)○ Bash (apt-get)

● Oracle Java 1.8 (ARM)● SSH

Environment

Page 23: Raspberry pi a la cfml

● PuTTY● IP Address?? (Router, Nmap)● CommandBox 2.0.0 beta

○ REPL○ ForgeBox○ Embedded Server

Tools

Page 24: Raspberry pi a la cfml

/etc/apt/sources.list.d/box.list

$> apt-get install commandbox

/usr/bin/box

$> box version

Install CommandBox

Page 25: Raspberry pi a la cfml

myFile.cfm

<cfoutput>#now()#</cfoutput>

$> box myFile.cfm

Run CFML!

Page 26: Raspberry pi a la cfml

myScript

#! /usr/bin/env box<cfoutput>#now()#</cfoutput>

$> chmod a+x myScript$> ./myScript

Run CFML!

Page 27: Raspberry pi a la cfml

$> box

CommandBox> install contentbox

CommandBox> start --rewritesEnabled

In-memory H2 DB

Install ContentBox

Page 28: Raspberry pi a la cfml

Install ContentBox

Page 29: Raspberry pi a la cfml

#!/bin/sh

# Get current CPU usage (10-second average, actually)top -bn 2 -d 10 | grep '^%Cpu' | tail -n 1 | gawk '{print $2+$4+$6}' >> ~/stats.txt

<div style="float:right;">#cb.widget("cpu-load")#

</div>

Adding CPU Load

Page 30: Raspberry pi a la cfml

Adding CPU Load

“Flot” JS graphing lib

Page 31: Raspberry pi a la cfml

#!/bin/sh

# Get current system memory max and usage, in that ordermem_system=`free -m | grep Mem: | gawk '{print $2,$3}'`

# Start by getting the pid of the largest java processjava_pid=`top -b -n 1|awk '{if ($1~/[0-9]+/) {if ($5~/m/) {$5=int($5*1024*1024)};print}}'|sort -k5rn,5 | grep java | head -n1 | gawk '{print $1}'`

# Get the actual heap usagemem_heap=`jstat -gc $java_pid | tail -n 1 | gawk '{print ($1+$2+$5+$7+$9)/1000,($3+$4+$6+$8+$10)/1000}'`

Adding Memory Usage

Page 32: Raspberry pi a la cfml

#cb.widget("mem-load")#

Adding Memory Usage

Page 33: Raspberry pi a la cfml

Rate Limiter installed

Posted to Reddit!

Page 34: Raspberry pi a la cfml

Performance test parameters

● No overclocking● Bumped heap size to 768 MB● Simple page with #now()# output● Use CLI load tool call “Siege”● Started with 1 thread and increased to 100 threads

How fast does this baby go?

Page 35: Raspberry pi a la cfml

#!/bin/bash

url="http://192.168.1.xxx/bench/"reqs=5000

NUMS="1 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100"

for NUM in $NUMSdo

RPS=`siege -r $((reqs/NUM)) -c $NUM "$url" 2>&1 | grep "Transaction rate:" | awk '{print $3}'`

echo -e "$NUM\t$RPS"done

How fast does this baby go?

Page 36: Raspberry pi a la cfml

How fast does this baby go?

1000 request per second!

Page 37: Raspberry pi a la cfml

What’s Next?

Page 38: Raspberry pi a la cfml

GPIO(General Purpose Input Output)

● 40 pins of wonderment○ 8 Ground pins○ 2 +3.3v pins (50 mA max)○ 2 +5v pins (direct current from power supply )○ 28 digital pins 3.3v “high” (50 mA max)

● Three different naming schemes○ Broadcom (BCM) chip numbers○ Physical header position○ Wiring Pi Numbers

Page 39: Raspberry pi a la cfml

GPIO(General Purpose Input Output)

Page 40: Raspberry pi a la cfml

GPIO(General Purpose Input Output)

● Cobbler (breakout) board● Solderless Breadboard● Red LED● 330 Ohm resistor● Hook in series between

digital pin and ground

Page 41: Raspberry pi a la cfml

Pi4J

● Java-based library for interacting with GPIO pins● Wraps “native” JNI calls to C library● Easy to use from CFML!

Yum!!

Page 42: Raspberry pi a la cfml

Pi4J

$> curl -s get.pi4j.com | sudo bash

$> cp /opt/pi4j/lib/pi4j-core.jar ~/.CommandBox/lib/$> cp /opt/pi4j/lib/pi4j-device.jar ~/.CommandBox/lib/$> cp /opt/pi4j/lib/pi4j-service.jar ~/.CommandBox/lib/$> cp /opt/pi4j/lib/pi4j-gpio-extension.jar ~/.CommandBox/lib/

Page 43: Raspberry pi a la cfml

CommandBox REPL + Pi4J =Blinky Blinky LED

GPIO = createObject( 'java', 'com.pi4j.io.gpio.GpioFactory').getInstance()

pinState = createObject( 'java', 'com.pi4j.io.gpio.PinState')

Raspipin = createObject( 'java', 'com.pi4j.io.gpio.RaspiPin')

LED = GPIO.provisionDigitalOutputPin( RaspiPin.GPIO_01, "MyLED", PinState.HIGH)

Page 44: Raspberry pi a la cfml

CommandBox REPL + Pi4J =Blinky Blinky LED

// Have you tried turning it // off and back on again?LED.low()LED.high()

// Toggle the current stateLED.toggle()

// On and back off onceLED.pulse( 2000 )

Page 45: Raspberry pi a la cfml

The (LED) Matrix has you

64 LEDs (8x8)

Page 46: Raspberry pi a la cfml

The (LED) Matrix has you

Only 16 pins!

Page 47: Raspberry pi a la cfml

The (LED) Matrix has you

Page 48: Raspberry pi a la cfml

The (LED) Matrix has you

--Multiplexing--Only one column can be lit at a time.

Page 49: Raspberry pi a la cfml

The (LED) Matrix has you

Inline 330 Ohm resistor on each rowEach column switched to ground via NPN transistor

Page 50: Raspberry pi a la cfml

The (LED) Matrix has you

CFMLRedraw each column > 60 times a second

Page 51: Raspberry pi a la cfml

The (LED) Matrix has you

Page 52: Raspberry pi a la cfml

Shift Your Focus

Shift Register

Page 53: Raspberry pi a la cfml

Shift Your Focus

SIPO -- Serial In, Parallel Out

Page 54: Raspberry pi a la cfml

Shift Your Focus

1 0 1 0 1 0 1 0

Bit bangingAllows transfer of large amount of data

over a few wires in “chunks”

Page 55: Raspberry pi a la cfml

Shift Your Focus

5 input wires drives 16 output

Data

ClockLatch

12345678910111213141516

5VGND

Page 56: Raspberry pi a la cfml

Shift Your Focus

Page 57: Raspberry pi a la cfml

Design In Flux

Page 58: Raspberry pi a la cfml

Design In Flux

Page 59: Raspberry pi a la cfml

Wired To The Brim

Page 60: Raspberry pi a la cfml

Wired To The Brim

Page 61: Raspberry pi a la cfml

“Smiley” animation

delay 10000frame0011110001000010101001011000000110100101100110010100001000111100

Page 62: Raspberry pi a la cfml

The Code

https://github.com/bdw429s/CFML-Pi-Hat/

Page 63: Raspberry pi a la cfml

Is that bacon I smell?

Page 64: Raspberry pi a la cfml

Is that bacon I smell?

Page 65: Raspberry pi a la cfml

What’s Next?

● Interactive projects (control from web)● Clustered Pis (CFML, Couchbase, etc)● Home Automation● CFGPIO library● What will you build?