static String[] GpioChannels = { "0", "1", "4" }; /* ... */ /** * @param args the command line arguments */ public static void main(String[] args) { FileWriter[] commandChannels; try { /*** Init GPIO port for output ***/ // Open file handles to GPIO port unexport and export controls FileWriter unexportFile = new FileWriter("/sys/class/gpio/unexport"); FileWriter exportFile = new FileWriter("/sys/class/gpio/export"); for (String gpioChannel : GpioChannels) { System.out.println(gpioChannel); // Reset the port File exportFileCheck = new File("/sys/class/gpio/gpio"+ gpioChannel); if (exportFileCheck.exists()) { unexportFile.write(gpioChannel); unexportFile.flush(); } // Set the port for use exportFile.write(gpioChannel); exportFile.flush(); // Open file handle to port input/output control FileWriter directionFile = new FileWriter("/sys/class/gpio/gpio" + gpioChannel + "/direction"); // Set port for output directionFile.write(GPIO_OUT); directionFile.flush(); } /* ... */ // Set up a GPIO ports as a command channels FileWriter heatChannel = new FileWriter("/sys/class/gpio/gpio" + GpioChannels[0] + "/value"); FileWriter fanChannel = new FileWriter("/sys/class/gpio/gpio" + GpioChannels[1] + "/value"); FileWriter acChannel = new FileWriter("/sys/class/gpio/gpio" + GpioChannels[2] + "/value"); // TEST Cycle all 5 min. on, 2 min. off // HIGH: Set GPIO port ON heatChannel.write(GPIO_ON); heatChannel.flush(); java.lang.Thread.sleep(300000); // LOW: Set GPIO port OFF heatChannel.write(GPIO_OFF); heatChannel.flush(); java.lang.Thread.sleep(120000); // HIGH: Set GPIO port ON fanChannel.write(GPIO_ON); fanChannel.flush(); java.lang.Thread.sleep(300000); // LOW: Set GPIO port OFF fanChannel.write(GPIO_OFF); fanChannel.flush(); java.lang.Thread.sleep(120000); // HIGH: Set GPIO port ON acChannel.write(GPIO_ON); acChannel.flush(); java.lang.Thread.sleep(300000); // LOW: Set GPIO port OFF acChannel.write(GPIO_OFF); acChannel.flush(); java.lang.Thread.sleep(120000); } } catch (Exception exception) { exception.printStackTrace(); } } |
Pretty straight-forward stuff. It's easy when you use Java SE Embedded technology and a Raspberry Pi. Hey, someone should trademark that...
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 1)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 2)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 3)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 4)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 5)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 6)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 7)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 8)
<<< Previous | Next >>>
