Wednesday Jul 23, 2014

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 >>>

Tuesday Jul 01, 2014

Jini IoT Edition: Connecting the Emerging Internet of Things Silos

For those who were around in the days of Sun Microsystems, Inc., you might remember Jini technology which was a cool network architecture for distributed systems, devices and services.

Hmmm... where have we recently heard that before? Does it sound similar to... the Internet of Things (IoT)???

See:

Jini IoT Edition

Here's a quote:

 In fact, in the late 90s, Sun Microsystems 
 defined a Java-based standard called Jini - 
 which was a network architecture comprised 
 of distributed systems, devices and services. 
 Jini talked about connected devices, both in 
 the consumer space and the enterprise. In a 
 manner of speaking, Jini was a precursor of 
 the IOT, but none of the above mentioned 
 supporting technologies existed at that time 
 and due to this and few other reasons. Jini 
 never made it to mainstream.
Well, yes. Jini was the precursor to IoT. And, there's no reason why it can't come back now that today's available technology has finally caught up with the concept. A Jini IoT Edition could be the driver to connect all those disparate silos forming for the Internet of Things, everything from Google's Nest API's, to Apple's HomeKit, to AllJoyn, Belkin's WeMo, MQTT, Tesla cars, you name it! Jini IoT Edition has the chance to tie all those scattered silos together with Java API's.

It's nothing new. It's just been sitting in there on the back shelf in a bottle, waiting for the right time to come back out and show its inherent quality: bringing together devices, services, and distributed systems. It's time to let it back out of that bottle. This time, there's no going back...

About

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

Search

Archives
« July 2014 »
SunMonTueWedThuFriSat
  
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
24
25
26
27
28
29
30
31
  
       
Today