PI4J in Struts2 Action

Skip to first unread message

Sławomir Korman

Apr 1, 2020, 12:55:30 AM4/1/20
to Pi4J

I liked mych PI4J I have a question regaring usung PI4J in Struts2 Web framework. 

I wanted to add contol of GPIO in Struts2 action but I get a error 
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

        // --------------------------------------------------------------------------

           output.setState(PinState.LOW); // or ... output.high();

        // wait

        output.setState(PinState.HIGH); // or ... output.high();

return SUCCESS;

I run Struts2 on Tomcat8 container, Maybe do I need to setup more in RapsPi device? 

Please let me know. 

Reply all
Reply to author
0 new messages