I am plugging away working with my Pi. I went back to the Ada Fruit Site, and started working on one of the tutorials from the part I purchased – https://www.adafruit.com/products/2125 I want to be able to demonstrate a simple wiring with my Pi works.
I selected Email Notifier. I read through it, and realized I needed to convert it to work for the B+ model. The pi4j website has a nice diagram for the pins http://pi4j.com/images/j8header-b-plus-large.png and I simplified the test a bit.
#!/usr/bin/env python | |
#REF https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds/python-script | |
import RPi.GPIO as GPIO | |
import time | |
GPIO.setwarnings(True) | |
GPIO.setmode(GPIO.BCM) | |
GREEN_LED = 23 | |
GPIO.setup(GREEN_LED, GPIO.OUT) | |
def loop(): | |
GPIO.output(GREEN_LED, True) | |
time.sleep(100) | |
if __name__ == '__main__': | |
try: | |
print 'Press Ctrl-C to quit.' | |
while True: | |
loop() | |
finally: | |
GPIO.cleanup() |
pi@seconds ~ $ sudo python testPi.py

I added the pi4j dependency to my maven pom
<dependency> <groupId>com.pi4j</groupId> <artifactId>pi4j-core</artifactId> <version>1.0</version> </dependency>
I create a servlet which replicated the same code from before (GPIO).
package bastide.pi.bbq; | |
import java.io.IOException; | |
import javax.servlet.ServletException; | |
import javax.servlet.annotation.WebServlet; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import com.pi4j.io.gpio.GpioController; | |
import com.pi4j.io.gpio.GpioFactory; | |
import com.pi4j.io.gpio.GpioPinDigitalOutput; | |
import com.pi4j.io.gpio.PinMode; | |
import com.pi4j.io.gpio.PinState; | |
import com.pi4j.io.gpio.RaspiPin; | |
/** | |
* Servlet implementation class Control | |
*/ | |
@WebServlet("/Control") | |
public class Control extends HttpServlet { | |
private static final long serialVersionUID = 1L; | |
/** | |
* @see HttpServlet#HttpServlet() | |
*/ | |
public Control() { | |
super(); | |
// TODO Auto-generated constructor stub | |
} | |
/** | |
* simple processing of the status flag for the servlet | |
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) | |
*/ | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
String param = request.getParameter("status"); | |
if(param!=null && !param.isEmpty()){ | |
boolean status = Boolean.parseBoolean(param); | |
final GpioController gpio = GpioFactory.getInstance(); | |
// RaspiPin.GPIO_23); | |
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_23, "MyLED", PinState.HIGH); | |
gpio.setMode(PinMode.DIGITAL_OUTPUT, pin); | |
System.out.println("--> GPIO state should be: " + status); | |
} | |
} | |
} |
I copied the war file to the local webapp directory, and restarted jetty
pi@seconds /opt/jetty/web/bbq/webapps $ sudo cp ~/pi.webapp.war ./ pi@seconds /opt/jetty/web/bbq/webapps $ sudo chown jetty:jetty pi.webapp.war pi@seconds /opt/jetty/web/bbq/webapps $ sudo /etc/init.d/jetty restart
Refer to https://wiki.eclipse.org/Jetty/Howto/Deploy_Web_Applications and I did have to add –module=jsp to the start.ini for my web configuration.
I hit the servlet – http://192.168.1.200/pi.webapp/Control?status=true

Which makes sense, since “Software using the Pi4J library must be run with ROOT level permissions.” (actually it doesn’t since I am running as root)…
Issues remain. I’ll tackle them on a different day … Part 5 …