Raspberry Pi – Part II – Get Up and Going with Java

In recent weeks, I haven’t revisited the Raspberry Pi – Running, Vacation, Work have conspired to keep me away from hobby project.

I’ve stared at the parts long enough, and decide to plug the Raspberry Pi base into the wired network. I plugged in the Raspberry Pi into the Power outlet, and I got the Red Light.  I logged into my router to see if the Pi picked up the Raspberry Pi, and I found the IP from my routers IP reservations table.   I was able to SSH into the Pi and quickly check the release version ( cat issue ) – Raspbian GNU/Linux 7 \n \l.

Headless + SSH + Version

I turned on the SSH server using sudo raspi-config and the advanced options.

The first thing I thought – Upgrade / Update to get the latest environment for the Raspberry Pi.  It’s a good start – always good to be up-to-date. Per the documentation, it may be necessary to run – sudo apt-get clean.

sudo apt-get upgrade
sudo apt-get update

The raspi-config is another item that may need to be updated.   The update goes out and queries for the latest raspi-config, installs and relaunches the raspi-config.

sudo raspi-config
Select Option 8 - Advanced Options
Selection Option A0 - Update 
Select Yes
raspi-config
raspi-config

Next, I looked updated the Java version.  From reading the documentation, the next versions of the Pi are going to automatically include the Java installs.

sudo apt-get update && sudo apt-get install oracle-java7-jdk
Java Installation
Java Installation

I grabbed the Pi4J project jar files. The Pi4J is an opensource project which has some great details on PINOUT and boilerplate java code to access the underlying pin readouts.  I ran some quick code to get the latest snapshot installed.

wget http://get.pi4j.com/download/pi4j-1.1-SNAPSHOT.deb
sudo dpkg -i pi4j-1.1-SNAPSHOT.deb

WGET
WGET

dpkg
dpkg

Pi4J is also installed on the Sonatype repositories and developed on GitHub.  Pi4J includes a script for managing updates.   It’s very convenient with the Apache 2.0 License.

I was ready run a sample program – Get Sample, Compile and Run.

wget https://raw.githubusercontent.com/Pi4J/pi4j/master/pi4j-example/src/main/java/ListenGpioExample.java
pi4j ListenGpioExample.java
pi4j -run ListenGpioExample
First Sample
First Sample

Eventually, I am going to get to the point where I use the diagram from Pi4j.  The future efforts are going to take some time to get to – This step was the right step in the direction I want to go.  BBQ Champion.

Secrets to Debugging Network Traffic

As many of you know, I am Java Programmer and a cURL fan. When I am demonstrating an API to a customer or another IBMer, I tend to default to either method to demonstrate the API.

I was demonstrating a download API that was being redirected, and throwing an error on a different Node.  In order to debug the traffic, I used a couple of different methods.

1 – For Java

I added -Djavax.net.debug=ssl:handshake:verbose  to the Java VM Arguments.  In Eclipse, I configure the Run Configuration -> VM Arguments.

java -Djavax.net.debug=ssl:handshake:verbose  MyAPIDemo

I absolutely make sure you have enough buffer in your console window.  I right click and update to a 100,000 lines.  I like to keep it as high as possible to capture all the details.

Scroll Through the output and find out what actually happened in the request.

2 – For cURL

I add -vv which is super verbose to the command

curl -H "Authorization: Basic asdfljkfasdf" https://api.com/api -vv

I read through and find out why my API failed.

You can read more about the configuration in the IBM JDK Documentation.