Raspberry Pi a la CFML
-
Upload
devobjective -
Category
Technology
-
view
87 -
download
1
Transcript of 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
● $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?
● 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…
● NOOBS● Raspbian Linux (Debian)
○ Gnome Desktop (Pi Store)○ Bash (apt-get)
● Oracle Java 1.8 (ARM)● SSH
Environment
/etc/apt/sources.list.d/box.list
$> apt-get install commandbox
/usr/bin/box
$> box version
Install CommandBox
myScript
#! /usr/bin/env box<cfoutput>#now()#</cfoutput>
$> chmod a+x myScript$> ./myScript
Run CFML!
$> box
CommandBox> install contentbox
CommandBox> start --rewritesEnabled
In-memory H2 DB
Install ContentBox
#!/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
#!/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
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?
#!/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?
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
GPIO(General Purpose Input Output)
● Cobbler (breakout) board● Solderless Breadboard● Red LED● 330 Ohm resistor● Hook in series between
digital pin and ground
Pi4J
● Java-based library for interacting with GPIO pins● Wraps “native” JNI calls to C library● Easy to use from CFML!
Yum!!
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/
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)
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 )
The (LED) Matrix has you
Inline 330 Ohm resistor on each rowEach column switched to ground via NPN transistor
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”