Thursday Apr 10, 2014

What's on my Java SE Embedded enabled desk at work?

If you ever wondered what I have on my messy Java SE Embedded technology-enabled desk in my office, here's you chance to see. Check out Vinicius Senger's video interview of me explaining the Internet of Things (IoT) devices on my desk.

See:

My Messy Desk with Java SE Embedded

Maybe I should have straightened out my desk better!

Oh, well... Nothing like having company over to see how messy your stuff is. ;-)

Tuesday Apr 01, 2014

Oracle IoT Device to Translate Cat Meows: Java SE Embedded on Raspberry Pi

Here's a new Oracle Internet of Things (IoT) Device that translates cat meows into readable text. You just need a Raspberry Pi device, a USB connected mic, and Java SE Embedded technology to program the meow-to-text recognition software using cloud-based, kitty-crowd-sourced, big data to do the translations.

The inventor here at Oracle was quoted as saying:

 "I was watching my cat the other day,
  and I thought, 'I wonder what my cat is 
  thinking...  If there were only a way to 
  use an IoT device to translate my cat's 
  thoughts and meows into human readable
  text.'". "A couple days later, I had a 
  prototype with parts from old stereo 
  equipment and a Raspberry Pi, and now, 
  nine months later, I have a $350 billion 
  startup company."
Thus was born the Oracle IoT Cat Meowerator, a next-generation automated cat translation device that taps into millions of cat meows stored over the web on an Oracle cloud database to deliver carefully translated meow-to-text conversions to your device.

The device, now available on Amazon.com for $299.99, includes a mic, a stuffed bird toy with catnip, meaty treats, and a Raspberry Pi controller board. It uses a Realtek 802.11b/g/n controller to link to the Internet over a home WiFi net like another access point and Java SE Embedded technology to let you know, "April Fools!".

Wednesday Mar 19, 2014

EclipseCon2014, slides for "Java SE Embedded 8 Compact Profiles"

Here are my slides from the recent EclipseCon 2014 conference on the topic of Java SE Embedded 8 Compact Profiles.

Download Link:

Click here to view slides in full window

It was fun to present this talk at EclipseCon 2014. If you attended the talk, thanks from coming by!

Friday Mar 14, 2014

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

We now have power to your Raspberry Pi. Next, we need to hook up the cool LCD Touchscreen from adafruit.com so that your Java SE Embedded thermostat app will have a UI. Lady Ada has some rockin' cool gear for your Raspberry Pi at her Web site!

See the cool video demo of the TFT touchscreen below:

To hook up her LCD Touchscreen to your RPi so that your Java SE Embedded app can use it, just follow these two sets of instructions from adafruit.com.

First do the assembly: TFT touchscreen assembly

Next do the software installation: TFT touchscreen software

That's it for this part. You can also check out the other steps at the adafruit.com Web site for screen calibration and other optional set-up steps. But, with the above minimal steps you now have a working touchscreen.

Next up, we will connect the PiFace for the relays needed to turn on and off your furnace and A/C via a Java SE Embedded app. That's when the stuff gets real... Or, sparks fly... One, or the other. :-)

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)
<<< Previous  | Next >>>

Wednesday Mar 05, 2014

The Path to a $16 Billion Acquisition? Build a Java ME App

As everyone saw in the press already, Facebook bought WhatsApp (maker of the startup mobile messaging app and service) for a hefty $16 billion. There was a lot of armchair analysis done just after the announcement, on how WhatsApp could be worth $16 billion. Here's a blog post (not mine) from the TextIt Blog, written by makers of the TextIt tool for SMS apps, that concludes the answer is Java ME technology (J2ME), and that Facebook bought WhatsApp for $16 billion because the WhatsApp Java ME port is available for feature phones, which if you look worldwide, still outnumber smartphones by a lot (a fact many developers and entrepreneurs overlook to their detriment).

See:

Java ME tech is the Answer

Here's a quote:

 So it finally happened, Facebook snatched 
 up WhatsApp for the not so bargain price of 
 $16B to the simultaneous head explosion of 
 every entrepreneur in Silicon Valley. A 
 common cry echoed around the world "But, 
 but, how is WhatsApp any different than 
 iMessage / Facebook Messenger / Hangouts?"

 To that, I have one answer: J2ME
So, even though it might not happen the same way for your mobile startup, you might want to consider the analysis by the TextIt blog post, that if you want to think big for mobile, you should consider a Java ME port of your mobile app to make sure you cover the whole market, not just the smaller smartphone (iOS and Android) market. Apparently, Mark Zuckerberg and Facebook did... :-)

Wednesday Feb 19, 2014

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

So, you've now added your Bridge Rectifier and Transformer to your $3.2bln Nest Startup prototype. You just need to connect to power up your Raspberry Pi.

This next step is pretty straight-forward. To make life easy, you should buy a USB A Jack to Wire Lead connector at element14 or Newark Electronics: here. This jack will allow you to plug in a typical micro USB cable to power up your RPi.

After you purchase the USB A Jack to Wire Lead connector (above), see the spec sheet for details on how to hook it up to your Transformer: here.

Then, connect the black wire of your USB A Jack to your Transformer GROUND OUT (-) pad by soldering it together, and connect the red wire to your Transformer POWER OUT (+) pad by soldering those together. That's it!

Plug in one end of a standard micro USB cable to your USB A Jack, and the other end to your Raspberry Pi. Then connect your 24VAC power from your house thermostat wiring to your breadboard Bridge Rectifier as mentioned in Part 3/Step 4 and turn your circuit breaker back on, or use a temporary power source on your workbench as described in the later section of Part 3/Step 4 to test it.

If you reach this point and you haven't fried your Raspberry Pi, then that's a very good thing. If you accidentally see white smoke coming out of your Raspberry Pi board, shout out your favorite expletive and quickly unplug everything. But don't worry, just go back to Part 1 and buy another one. Heck, they're just $35 each! Buy, 2 or 3 more, just in case... ;-) Wouldn't hurt.

When you reach this point, and your RPi powers up correctly with very little or no swearing, do a little dance and get ready for the next step in building your own $3.2bln Nest Startup, which is where you connect up the LCD touchscreen.

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)
<<< Previous  | Next >>>

Monday Feb 03, 2014

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

If you are this far along, it means you do have a "C" wire at your thermostat. Yay! That means you can connect the Bridge Rectifier GBU608 and the DC to DC step-down transformer from your thermostat wires to power your Raspberry Pi from the 24VAC of your thermostat wiring. We are using the C wire and either the (Rh or Rc wire) or the R wire to power the RPi, since one of the "R" wires is considered in AC terms "hot" and the "C" wire is considered "neutral".

NOTE: You need a "hot" wire and a "neutral" wire in AC household electrical circuits to complete or close an AC circuit. With most U.S. household thermostats, we are working with a lower 24VAC standard, and not your typical 110VAC found in U.S. homes. If your thermostat happens to be a higher voltage 110VAC thermostat, stop here and do not proceed. Your wiring for a 110VAC thermostat is not the same as the 24VAC we need for this project. If you are unsure whether your thermostat is 24VAC or 110VAC, ask an electrician friend or electrical contractor to check for you.

As a review, the Bridge Rectifier turns the 24VAC of your furnace relay from 24 volts of AC power to 33 volts DC power, and the step-down transformer turns the 33 volts DC down to 5 volts DC for the Raspberry Pi (and all its peripherals).

As with any $3.2 billion startup, you begin with a prototype, and that prototype is typically built using a breadboard, so that you can easily put it together and change it if necessary.

  1. So find a hobby electronic breadboard, and add your GBU608 Bridge Rectifier. In this part of the project you will run the inner two wires to connect from the breadboard to your "C" and one of your "R" wires of your thermostat (refer to the pinout diagram above)
  2. Use a wire connected to the notched edge pin of your GBU608 which represents the positive terminal to solder to the positive "IN" pad on your DC to DC Voltage Step-Down Transformer, and do the same with your unnotched edge pin of your GBU608 which is the negative connector and solder that to the negative "IN" pad on your DC to DC Voltage Step-Down Transformer.
  3. Solder two separate wires to the positive and negative "OUT" pads of your DC to DC Voltage Step-Down transformer
  4. Connect the two inner pins (marked with the "~" symbol) of your GBU608 Bridge Rectifier to your thermostat wires as described in Step #1: one inner pin connects to the "C" wire of your thermostat and the other inner pin connects to one of the "R" wires (or better yet for workbench development purposes, connect them to a temporary 24VAC power supply like this one to represent the thermostat power as you develop on your bench first).
  5. Use a voltmeter to measure the OUT pads of your DC to DC Voltage Step-Down transformer and adjust the screw of the transformer until your voltmeter reads 5 volts.

Once you have the screw set on your transformer, then your are ready to connect your Raspberry Pi in the next step... Fun!

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)
<<< Previous  | Next >>>

Monday Jan 27, 2014

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

So, let's get started in building your own $3.2 billion (with a "b") Nest Startup using a Raspberry Pi, some hobby electronic parts, and Java SE Embedded Technology. The journey of a $3.2 billion startup begins with a single step-down transformer... er, or something like that.

First, we'll need a crash course in home thermostat technology. Here in the U.S., if you first flip off the circuit breaker to your home heating furnace and A/C, then take off the thermostat panel in your house, you should see these standardized labeled wires (with various colors of wires that are not standardized):

    Red - R - 24VAC
         or
    Red - Rh - 24VAC (dedicated to heat call)
    Red - Rc - 24VAC (dedicated to cooling call)

    Green - G - Fan on
    White - W - Heat call
    Yellow - Y - Cool call
    Blue or Black - C - Common

If you see a wire labeled "C" (Common) and the rest of the labeled wires (above), then you are OK. If you do not see the "C" label on a wire, you must ask an electrician friend or hire an electrical contractor to run the common "C" wire from a furnace relay to your thermostat. Otherwise, if you do not have the "C" wire at your thermostat, stop here since the "C" wire is needed to power the Raspberry Pi and especially for the Wi-Fi adapter to have enough power to allow your new SmartThermostat to be networked.

If after one way or another you do have a "C" wire at your thermostat, then you are ready for the first step which is to connect the Bridge Rectifier GBU608 and the DC to DC step-down transformer from your Raspberry Pi to your thermostat wires to power it from the 24VAC of your thermostat wiring (C and either Rh or Rc or R). The Bridge Rectifier turns the 24VAC of your furnace relay from 24 volts of AC power to 33 volts DC power, and the step-down transformer turns the 33 volts DC down to 5 volts DC for the Raspberry Pi (and all its peripherals).

Come back to the next blog post to see how that's done... It's a fun step since it's your first one! ;-)

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)
<<< Previous  | Next >>>

Wednesday Jan 22, 2014

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

As we all saw recently, the company that starts with the letter "G" up Highway 101 in Mountain View bought Nest Labs for $3.2 billion (with a "b"), maker of the Internet of Things (IoT) Nest thermostat. Well, here's your chance in this new Java SE Embedded IoT blog series, to learn how to build your own $3.2 billion Nest Startup using a Raspberry Pi, some hobby electronic parts, and Java SE Embedded Technology.

This blog series was inspired by Spark Team's Arduino Based blog post at the spark.io. But, we'll use a more powerful but still inexpensive Raspberry Pi, and we'll base the software on Java SE Embedded which is a much more powerful programming language and platform than you can ever find on the Arduino.

This project will need the following parts:

So, for the low total cost of about $128.30 (plus tax and shipping) you can build your own $3.2 billion IoT startup company. Well... maybe, the start of a $3.2 billion IoT startup company, but you'll have a nifty IoT Java SE Embedded enabled home thermostat in the end, regardless. And, that's just as good as a $3.2 billion IoT startup, right? ;-)

Come back for the next steps in this series, to get you on your way...

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)
<<< Previous  | Next >>>

Friday Jan 10, 2014

Happy Java SE Embedded Enabled Internet of Things (IoT) New Year!

Whew! That's a mouthful to say. How about if I just say, "Happy Java-Is-the-Best-for-IoT New Year!" That's better. In 2014, for this blog I hope to explore new and interesting ways to make your Internet of Things smarter by using Java SE Embedded.

As a look back at 2013, you can see by my blog statistics (in the picture) that it seems like there were a lot of embedded developers out there who were interested in the blossoming IoT topics that my blog covered over the past 12 months.

You can also see my blog's Page Views, Unique Visits, and Returning Visits for all of 2013 vs. all of 2012 (for comparison).

See:

My Blog 2013 vs. 2012 Summary

The overall numbers for 2013 look great, with 152,262 unique visitors who stopped to read my blog last year (2013) compared to 108,162 of you who stopped by in the previous year (2012). And, the 2013 visitors read 202,818 pages of my blog for all of last year. Whew! That's a lot of pages read!

Thanks to all who follow my blog! As you can also see in the chart, last year there were 16,183 returning visitors to my blog compared to 7,738 returning visitors in 2012. So, hopefully, I will keep posting technical updates, DIY IoT projects, and interesting news and articles about Java SE Embedded in 2014 to match what you all wanted in 2013 when there was such a big uptick in my return visitors.

Leave me a comment if there are any specific topics you'd like me to cover related to Java SE Embedded, Internet of Things, and how to make embedded devices smarter for 2014.

In the meantime, I hope everyone has a Happy New Year! :-D

Tuesday Dec 24, 2013

Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)

Well, this wraps up the Internet of Things (IoT) Christmas Special! Hope you enjoyed seeing the steps for creating the Java SE Embedded enabled Santa Detector!

The last step is to place the Raspberry Pi device connected to your Parallax PIR motion sensor nearby a plate of cookies and a glass of milk tonight. Then, start your Java SE Embedded SantaDetector.java app on the RPi before you go to bed, and tomorrow morning you and your child should see a tweet around midnight that shows that Santa came by.

(NOTE to parents [VERY IMPORTANT]: Remember to, you know, do the "thing" with the "thing" at around *mumble-mumble*. Got it? Nudge-nudge, wink-wink...) ;-)

Here's the full compilable Java source code again for reference:
https://java.net/projects/orbit/downloads/download/SantaDetector.java

That's a wrap!

Have a very Merry Christmas and a Happy Internet of Things (IoT) New Year! ;-)

See the full series of steps:
Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)
<<< Previous  | Next >>>

Monday Dec 23, 2013

Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)

So, let's take a closer look at the Java SE Embedded code snippet that will send out a tweet when the Santa Detector Raspberry Pi motion sensor is triggered, which will let the Oracle cloud and the Twitterverse know when Santa has arrived at your house. And, if you are doing this project with your child, it will prove once and for all that yes, there is a Santa Claus. Yay!

Here's the full compilable Java source code again for reference:
https://java.net/projects/orbit/downloads/download/SantaDetector.java

0. First, you need to have a Twitter 
account and you need to create your 
own Santa Detector Twitter app to 
make this work.  

Just follow the steps here:
Create Santa Detector Twitter App

And, make sure to do the following extra steps to make your Twitter app "Read and Write" enabled:

 1. Go to your Twitter app account by signing
  in with our Twitter login info:
    https://dev.twitter.com/
 2. Select your account icon -> My Applications
 3. Select the Santa Detector app (To create the
  app: see above)
 4. Click on the Settings tab
 5. In the section "Application Type Access:",
  select "Read and Write"
 6. Check the box for "Allow this application 
  to be used to Sign in with Twitter"
 7. Click "Update this Twitter's app settings"
 8. Click on the Details tab
 9. Refresh your Web browser
10. Make sure the Access level says: 
  "Read and write"
11. Copy the Twitter app information from the
  page into the SantaDetector.java code (Java
  variables near the top of the file):
   OAuth setting: Consumer Key
   OAuth setting: Consumer Secret
   Access token: Access token
   Access token: Access token secret

Next, take a look at the code snippet in the SantaDetector.java file that will send the tweet by calling the Java method tweetStatus():

 static void tweetStatus(String statusStr) {

        boolean verboseFlag = true;
        String requestURIEnc = null;

        try {
            requestURIEnc = URLEncoder.encode(requestURI, "UTF-8");
        } catch (UnsupportedEncodingException uee) {
            uee.printStackTrace();
        }

        try {

            if (statusStr == null) {
                statusStr = "Tweet, tweet.  Hello world!";
            }

            // Construct encoded string, parameter encoded string, & data
            String statusEncStr = URLEncoder.encode(statusStr, "UTF-8");

            // Param encode status string twice: once for unsafe characters 
            //  String, once for escaping % for Signature base string
            String statusUnsafeEncStr = unsafeEncode(unsafeEncode(statusStr));

            String postData = "status=" + statusEncStr;

            // First set the default cookie manager
            CookieHandler.setDefault(new CookieManager(null,
                    CookiePolicy.ACCEPT_ALL));

            // Send postData
            URL url = new URL(requestURI);

            HttpsURLConnection conn = (HttpsURLConnection) 
		url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");

            // Get current date time with Calendar()
            Calendar cal = Calendar.getInstance();
            String timeStr = String.
                    valueOf(cal.getTimeInMillis()).substring(0, 10);

            String basestring = "POST&" + requestURIEnc
                    + "&oauth_consumer_key%3D" + consumerKey
                    + "%26oauth_nonce%3D5bffa3b2711bbcdaa4f301" + timeStr
                    + 
                   "%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D"
                    + timeStr + "%26oauth_token%3D" + accessToken
                    + "%26oauth_version%3D1.0" + "%26status%3D"
                    + statusUnsafeEncStr;

            String secretsStr = consumerSecret + "&" + accessTokenSecret;
            SecretKeySpec keySpec
                    = new SecretKeySpec(secretsStr.getBytes(),
                            "HmacSHA1");

            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(keySpec);
            byte[] result = mac.doFinal(basestring.getBytes());

            String signature = URLEncoder.encode(base64Encode(result), 
						 "UTF-8");

            String credentials
                    = "oauth_consumer_key=\"" + consumerKey + "\","
                    + "oauth_nonce=\"5bffa3b2711bbcdaa4f301" + timeStr
                    + "\","
                    + "oauth_signature=\"" + signature + "\","
                    + "oauth_signature_method=\"HMAC-SHA1\","
                    + "oauth_timestamp=\"" + timeStr + "\","
                    + "oauth_token=\""
                    + accessToken + "\","
                    + "oauth_version=\"1.0\"";

            conn.addRequestProperty("Authorization", "OAuth " + credentials);

            String lenStr = String.valueOf(postData.length());
            conn.setRequestProperty("Content-Length", lenStr);
            conn.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded");

            // Do as if you're using Firefox 3.6.3
            conn.setRequestProperty("User-Agent",
                    "Mozilla/5.0 (Windows; U; Windows NT 5.1; "
                    + "en-US; rv:1.9.2.3) Gecko/20100401");

            if (tweetFlag) {
                conn.connect();
                OutputStream output = conn.getOutputStream();

                output.write(postData.getBytes("UTF-8"));

                // Get the response
                InputStream response = conn.getInputStream();
                BufferedReader rd
                        = new BufferedReader(new InputStreamReader(response));
                String line;
                while ((line = rd.readLine()) != null) {
                    if (verboseFlag) {
                        System.out.println(line);
                    }
                }
                rd.close();
            }
            
            System.out.println("Tweet status = " + statusStr +
                    "\n basestring = " + basestring);

        } catch (IOException | NoSuchAlgorithmException |
                InvalidKeyException | IllegalStateException e) {
            e.printStackTrace();
        }
    }

You see that you can take the above code snippet and just make a tweetStatus library out of it. It is self contained as long as you add the following utilities that need to go along with it.

    public static String unsafeEncode(String input) {
        StringBuilder resultStr = new StringBuilder();
        for (char ch : input.toCharArray()) {
            if (isUnsafe(ch)) {
                resultStr.append('%');
                resultStr.append(toHex(ch / 16));
                resultStr.append(toHex(ch % 16));
            } else {
                resultStr.append(ch);
            }
        }
        return resultStr.toString();
    }

    private static char toHex(int ch) {
        return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
    }

    private static boolean isUnsafe(char ch) {
        if (ch > 128 || ch < 0) {
            return true;
        }
        return "$&+,/:;=?@ \"<>#%{}|\\^~[]`'!_*".indexOf(ch) >= 0;
    }

    private final static char[] BASE64CHARS
           = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
           .toCharArray();

    private static final int[] intChars = new int[128];

    /**
     * Translates the specified byte array into Base64 string.
     *
     * @param inputBuffer byte array (not null)
     * @return the translated Base64 string (not null)
     */
    public static String base64Encode(byte[] inputBuffer) {

        // Check if intChars array needs to be init'd
        if (intChars.length == 0) {
            for (int index = 0; index < BASE64CHARS.length; index++) {
                intChars[BASE64CHARS[index]] = index;
            }
        }

        int bufferSize = inputBuffer.length;
        char[] charArray = new char[((bufferSize + 2) / 3) * 4];
        int charIndex = 0;
        int inputIndex = 0;
        while (inputIndex < bufferSize) {
            byte byte0 = inputBuffer[inputIndex++];
            byte byte1 = (inputIndex < bufferSize)
                    ? inputBuffer[inputIndex++] : 0;
            byte byte2 = (inputIndex < bufferSize)
                    ? inputBuffer[inputIndex++] : 0;

            int mask = 0x3F;
            charArray[charIndex++] = BASE64CHARS[(byte0 >> 2) & mask];
            charArray[charIndex++] = BASE64CHARS[((byte0 << 4)
                    | ((byte1 & 0xFF) >> 4)) & mask];
            charArray[charIndex++] = BASE64CHARS[((byte1 << 2)
                    | ((byte2 & 0xFF) >> 6)) & mask];
            charArray[charIndex++] = BASE64CHARS[byte2 & mask];
        }

        switch (bufferSize % 3) {
            case 1:
                charArray[--charIndex] = '=';
            case 2:
                charArray[--charIndex] = '=';
        }

        return new String(charArray);
    }


So, that's all there is to it to enable your Santa Detector to tweet when Santa has arrived. In the next blog post, we'll wrap it all up and figure out where to place the Raspberry Pi with the sensor for best coverage...

It's almost Christmas Eve, so get ready! ;-)

See the full series of steps:
Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)
<<< Previous  | Next >>>

Sunday Dec 22, 2013

Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)

Admiral Ackbar Santa thinks our Santa Detector is a trap. Well, he's right! We are setting up our Internet of Things (IoT) Santa Detector to catch Santa in the act on Christmas Eve to tell the world whether Santa Claus exists.

(I have a sneaky suspicion that we will detect Santa Claus on Christmas Eve and prove his existence. But, that's just a hunch... ;-) )

Admiral Ackbar Santa really shouldn't worry. We're not really going to try to trap Santa, just tweet when he's detected by our Java SE Embedded application.

So, you've followed the directions, so far, now you just need the Java source code for the Java SE Embedded app to run on your Raspberry Pi connected with a Parallax PIR sensor.

Here's the full Java source code that you'll need:
https://java.net/projects/orbit/downloads/download/SantaDetector.java

Here's a code excerpt from the full file above of Java SE Embedded code that uses the GPIO port on your Raspberry Pi connected to the Parallax PIR sensor to read in a value to detect if Santa is standing in front of the strategically located bait, er, um... I mean, plate of cookies and glass of milk:

//
// Init GPIO port(s) for input
//

// 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("Activating GPIO port: "
		       + 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 input/output dir control of port
    FileWriter directionFile
	= new FileWriter("/sys/class/gpio/gpio"
			 + gpioChannel + "/direction");

    // Set port for input
    directionFile.write(GPIO_IN);
}
                
// Open RandomAccessFile handle for each GPIO port
for (int channum=0; channum < raf.length; channum++) {
    raf[channum] = new RandomAccessFile("/sys/class/gpio/gpio"
					+ GpioChannels[channum] + 
					"/value", "r");
}

//...


// Loop to keep reading sensor value
while (true) {
    int available;
            
	// Use RandomAccessFile handle to read in GPIO port value
	for (int channum=0; channum < raf.length; channum++) {
            
	    try {
		// Reset file seek pointer to read latest value 
		//   of GPIO port
		raf[channum].seek(0);
		raf[channum].read(inBytes);
	    } catch (IOException ioe) {
		ioe.printStackTrace();
	    }
                        
	    inLine = new String(inBytes);
            
	    // Check if "on" value was read
	    if (inLine.equals("1")) {

		// Specially mark value non-zero value
		gpioPortVal = 1;
		  
	    } else {
		// Else, no "on" value read
		gpioPortVal = 0;
	    }

	    System.out.println("Reading GPIO Port: " + 
			       GpioChannels[channum] +
			       "  Time: "+ timedateString + "  GPIO value = " + 
			       gpioPortVal);
	}
    }

So, as you can see in the code snippet above, the Java source code just keeps reading from the GPIO port where the PIR sensor is connected, whether it has a value of "0" (no motion detected) or "1" (motion detected), and that will tell us if Santa is there in front of the plate of cookies and glass of milk.

In the next blog post, we'll look at the Java code that will send out a Tweet when that happens, letting the cloud know when Santa has arrived at our location.

So, don't worry Admiral Ackbar Santa, it's all good! ;-)

See the full series of steps:
Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)
<<< Previous  | Next >>>

Friday Dec 20, 2013

Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)

Now, that you have all your parts, you should have this important part which is the motion sensor itself. It detects infrared motion and will light an internal LED and send a signal to the Java SE Embedded app when something (or someone like Santa Claus) passes in front of it.

The Raspberry Pi has enough power to also power this sensor, so you will next need to connect this part to your Raspberry Pi.

Just look at the next photo how it's done.

Flip the sensor over so that you can see the bottom of the circuit board where the labels are.

See: GPIO pin layout

Connect the left connector (OUT) to Pin #26 (GPIO07) on your Raspberry Pi GPIO bus. Connect the middle connector (VCC) to Pin #2 (+5 volts). And, connect the right connector (GND) to Pin #6 (GND) on your RPi.

And, that's it for the hardware part. Not too bad.

Next up we'll write a Java SE Embedded app to test the motion sensor. Santa won't have a chance this year... :-)

See the full series of steps:
Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)
<<< Previous  | Next >>>

Thursday Dec 19, 2013

Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)

Ho ho ho! It's time for an Internet of Things (IoT) Christmas Special project for Java SE Embedded on your Raspberry Pi. This one you can do with your kid. It's a Santa Detector, which was inspired by John Murphy's Arduino project.

This project will take a Parallax Passive Infra-Red sensor connected to your Raspberry Pi and a Java SE Embedded application code to send a Tweet when Santa has arrived at your house.

With this IoT Christmas Special project, there's going to be no way for Santa to sneak past your child this year. Heh, heh, heh... (or, should I say, "Ho, ho, ho"?) ;-)

Here is the parts list:

 1 Parallax PIR Sensor (Fry's #6726705)
 1 Raspberry Pi
 1 Milk and Cookies (for concealment)

So, go out and buy the parts above and come back here for the rest of the steps... "You better watch out, la-la-lala-laaa..."

See the full series of steps:
Internet of Things (IoT) Christmas Special: Santa Detector (Part 1)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 2)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 3)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 4)
Internet of Things (IoT) Christmas Special: Santa Detector (Part 5)
<<< Previous  | Next >>>

About

Hinkmond Wong's blog on making Machine to Machine (M2M) and the Incredible Internet of Things (IoT) smarter with Java Embedded Technologies

Search

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