Happy New Year Everyone.
English is not my native language so please be patient.
I'm trying to use a Raspberry Pi 2 (Model B) for alert me when some one open the case, using a limit switch and the GPIO pins. (This is not a Raspberry SE question)
At this moment I'm facing an issue with the GPIO pins, after following the pi4j examples (ListenGPIOExample.java) in console I tried to do in a web app; I'm using Apache Tomcat 7 (as root) and a very simple JSP page developed in netbeans for turn off/on a led. My code is the following:
<%@page import="com.pi4j.io.gpio.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="RPI.GPIO"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST">
<input type="submit" name="button" value="Button 1" />
<%
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, "MyLED", PinState.LOW);
if (request.getParameter("button") != null) {
try{
out.println("NO Error");
pin.toggle();
Thread.sleep(500);
pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF);
//gpio.shutdown();
//gpio.unprovisionPin(pin);
}
catch(Exception ex){
out.println("Error");
}
} else {}
%>
</form>
</body>
</html>
If I push the button, it's suposed to change the pin state, but whenever I try got the same error, HTTP 500 - com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 0
. Tried with several pins, same error.
As you can see in the code, the unprovision and the shutdown are commented, because the solutions post in here and here haven't work for me.
Thanks in advance for your help.