I am running the code at the bottom using java and Pi4j
library, pretty much the program checks is the pin is low and waits sometime before turning off the tv.
When I reboot my Raspberry and run the code, I get no issues. however when I close the program using CTR+C
and run again, sometimes I get the this error when I start the program, and I cannot read from the sensor :
wiringPiSetup: mmap failed: No such file or directory
and also the following error
file:/opt/jdk1.8.0/jre/lib/ext/jfxrt-controls.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
Exception in thread "Thread-5" java.lang.NullPointerException
at javafxapplication4.JavaFXApplication4.lambda$0(JavaFXApplication4.java:672)
at javafxapplication4.JavaFXApplication4$$Lambda$3.run(Unknown Source)
at java.lang.Thread.run(Thread.java:724)
and my code is
new Thread(() -> {
final GpioController gpioSensor = GpioFactory.getInstance();
sensor_lastTimerCall = System.currentTimeMillis();
final GpioPinDigitalInput sensor = gpioSensor.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);
sensor.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if (event.getState().isHigh()) {
sensor_lastTimerCall = System.currentTimeMillis();
ProcessBuilder processBuilder1 = new ProcessBuilder("bash", "-c", "echo \"as\" | cec-client -d 1 -s \"standby 0\" RPI");
try {
Process process1 = processBuilder1.start();
}catch (IOException ex) {
Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(event.getState().isLow()){sensorLow = true;}
}
});
System.out.println(" ... Motion Detection Starting.....");
for (;;) {
try {
Thread.sleep(1000);
long now = System.currentTimeMillis();
if (System.currentTimeMillis() > sensor_lastTimerCall + 360000 && sensorLow) {
System.out.println("All is quiet...");
ProcessBuilder processBuilder2 = new ProcessBuilder("bash", "-c", "echo \"standby 0000\" | cec-client -d 1 -s \"standby 0\" RPI");
try {
Process process2 = processBuilder2.start();
}catch (IOException ex) {
Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, ex);
}
sensor_lastTimerCall = now;
sensorLow = false;
}
} catch(InterruptedException ex) {
gpioSensor.shutdown();
Thread.currentThread().interrupt();
}
}
}).start();
}
any idea how to fix this?