I liked mych PI4J I have a question regaring usung PI4J in Struts2 Web framework.
bellow my sample class, This code is wroking when I run as main class in rapsbi 3b+ but when I put this into Struts action i get null error.
package com.action;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.ActionSupport;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class RelayAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
final static Logger logger = Logger.getLogger(RelayAction.class);
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
// provision gpio pin as an output pin and turn on
final GpioPinDigitalOutput output = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_23, "My Output", PinState.HIGH);
private String status;
public String execute() throws InterruptedException {
logger.error("Start execute : ");
// set shutdown state for this pin: keep as output pin, set to low state
output.setShutdownOptions(false, PinState.LOW);
// wait
Thread.sleep(500);
// --------------------------------------------------------------------------
output.setState(PinState.LOW); // or ... output.high();
// wait
Thread.sleep(500);
output.setState(PinState.HIGH); // or ... output.high();
gpio.shutdown();
return SUCCESS;
}
I run Struts2 on Tomcat8 container, Maybe do I need to setup more in RapsPi device?