How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 8)

Now, your Parallax Single Relay Board from your Raspberry Pi is connected to your furnace, fan, and A/C control wires. Let's just stop right there and soak that in.

Your Raspberry Pi is now the hardware equivalent to a Nest Thermostat. Nice work so far! You just need intelligent software to run the Raspberry Pi to control your home heating and A/C. And, of course, you don't want to use just any programming language to do that. You want your Raspberry Pi to be a smart Internet of Things (IoT) device, not a dumb device. So, you're going to need Java SE Embedded Technology.

Here's the simple Java code that will drive your relays to turn on your furnace, fan, and A/C. It's a test app that cycles your heat on for 5 minutes, then your fan on for 5 minutes, then your A/C on for 5 minutes with a rest period of 2 minutes in between.

    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... ;-)

Full series of steps:
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)
How to Build Your Own $3.2bln Nest Startup Using Java SE Embedded Tech (Part 9)
<<< Previous  | Next >>>

Comments:

Post a Comment:
Comments are closed for this entry.
About

Hinkmond Wong's blog on making the Internet of Things (IoT) smarter with Java Technologies

Search

Archives
« July 2015
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
22
23
25
26
28
29
30
31
 
       
Today