How have I not seen this before?

100 Reasons McDonald’s is better than the Navy

Finally, someone did it.

After moving into our house a couple of years ago I went through and replaced all of the incandescent light bulbs with LED equivalents.  It wasn’t a cheap project, but just from my back-of-the-napkin calculations, it should pay itself off in about 2 years of normal use.  And, considering that my household is about as far from normal as you can get, the payback period is most likely substantially shorter.

I still have a few fluorescent fixtures left, mainly small recessed lights above showers and bathtubs, with the notable exception being three 2-lamp 4′ fixtures in my garage.  Each bulb is 34 watts, so when my kids(wife) leave the garage lights on, they’re burning 200+ watts continuously.  It drives me bonkers, especially considering I think I could leave pretty much every other light in the house on at this point, and it wouldn’t consume that much energy.

I considered replacing the fixtures with LED equivalents, but being the lazy pragmatist that I am, I figured it was only a matter of time before someone made a drop-in replacement.  I wasn’t wrong.  Cruising the local Costco this weekend, I ran across these bulbs from Feit.  They were a little pricey, and I’m sure I could find them cheaper somewhere else [a quick search on Amazon points to me being a liar] but they were convenient, and I could always return them if they didn’t work.  The best part of these lamps is that they’re literally a drop-in (or twist-in) replacement, there’s no need to remove the existing ballast or re-wire the fixture.  At 17 watts per lamp, they’re a great replacement for each of the 34 watt bulbs.

I threw them in one of the fixtures when I got home, and I’m pleased to say that they work great.  They start off a little yellowish right when they first fire up, but brighten into a nice white light once they’ve warmed up for a few seconds.  I’m definitely pleased with these bulbs (so far) and will be replacing the bulbs in the other two fixtures shortly.

 

Sorry Linux, we’re just not meant to be… yet.

I had some use-’em-0r-lose-’em vacation days at work, so I decided to use them to clean up some of the miscellaneous projects I’ve been working on over the past year or so, and just hadn’t had the time to finish them off.  One of them was building a database server so I could migrate my MySQL database that I’ve been using for various applications that I’m writing off of my media server.  I figured that this would probably be a good time to take a peek at a fairly popular Linux distribution as the OS, as I’ve always been tempted to jump into learning a Unix-style OS.  I hear all the time about how the folks that know what they’re doing using Linux to run their stuff, so, why shouldn’t I?

I did a little research, put together a list of components that was probably a bit of an overkill for what I currently need, and headed down to Fry’s to pick them up.  Nothing spectacular or expensive, and it was all off-the-shelf stuff.  After being home for about 30 minutes, I had the thing all assembled and fired up.  I made a boot image of the latest version of Ubuntu on a USB drive, and I was off and running with my first Linux install.  It was actually very painless, and I was surprised at how easy it was to get everything set up – sorta.  I wasn’t super familiar with how the drives I had were going to be partitioned, so I pretty much just accepted the defaults for everything, except for the drives I planned on using in RAID-10 to house the main database files.  I was really impressed with how smooth the install went, and how fast I was up and running – with everything configured.  I didn’t have to download any updates or drivers, it all just pretty much worked right out of the box.

… and then things got interesting.

I am going to preface this next part with saying that my Google-fu is pretty strong, and I have a cursory understanding of permissions, file system structure, and the terminal.  My main media machine runs an earlier version of Ubuntu, and I’ve been able to get everything working that I’ve needed to on that.  It took a little work, and a little learning, but it wasn’t bad.  However, my experience with actually trying to set up ‘work’ applications was a whole different experience.  The first thing I wanted to do was create a RAID-10 volume from 4 128GB SSD’s.  It took me about 4 hours to figure out, and I had to follow a sequence I found from searching through various Ubuntu blogs and help sites, but I got it done.  I was quite proud of myself, even though I really didn’t have a good understanding of what I had actually done.  I was pretty relieved that I had actually gotten the thing to work, so I didn’t question it too much.  I bookmarked the site I referenced for the sequence, and went on about my business, hoping I never had to do that again.

I then installed MySQL server, which was the easiest thing in the world.  I do have to say that I really can appreciate the simplicity and ease of the ‘apt-get’ command.  With a simple one-line command I was able to install MySQL server no-problemo, super cool stuff there.  Where I really started to run into issues is when I tried to move the MySQL data directory onto the RAID-10 drive I had labored to create earlier.  I found several sites that had some semblance of a sequence on how to do it, with a few of them being very specific with the commands needed to make that happen.  But, to my dismay, I found I was using a newer distro of Ubuntu than any of the referenced sites were, and that was causing the sequence to not work for me.  I was running into issues with not being able to connect to the database initially, which I eventually found to be that the default install of MySQL had changed to only bind to 127.0.0.1 – easy enough to solve, but not very well documented.  I also had a lot of difficulty with the AppArmor ‘thing’ – this appeared to be a sticking point for a lot of other folks as well, as there was a decent collection of helpful posts on the subject, but unfortunately things seem to have changed with version 15+ of Ubuntu, as I could never get it to work quite right with what was presented in those posts.  I probably spent a good 6 or 7 hours trying to remedy that, which wasn’t too unexpected, as, again, I’m pretty much a novice when it comes to Linux.

I did finally get it all working though, which was awesome.  Again, I had done something, and it was working, but I wasn’t 100% sure of what I actually did, and severely doubted my ability to be able to do it again without the same amount of headache.  What finally blew the whole thing out of the water for me though was just trying to do some everyday simple things, like move export files over from a network share so I could import them into my shiny new database.  I somehow deleted the file browser from the application bar on the left hand side of the screen, and for the life of me, I couldn’t find out where that thing was to get it back.  And then I did some searching to try to find out where it was, and couldn’t locate it, so thing I searched for what I could type into the terminal to just bring the thing over myself… and I found about 10 different ways to do that, all of them being sequences of commands that really didn’t make sense.  Like, do I really need to install a bunch of stuff just to read a file off of a network share?  That didn’t seem friendly at all.  And I really didn’t feel like having to look all of that crap up again when I would inevitably have to transfer more files over.

When all was said and done, I had burned half of my three days off trying to solve these issues, and I was sure that I was going to eventually going to have to burn more time in the future messing around with this stuff again.  And, time is just something I don’t have a lot of right now.  I pulled myself away from the machine and realized I blew half of my time off that I had allotted for projects to something I could have done in a little under an hour had I used Windows 7.  So, I went back down to Fry’s and picked up a new copy, and I haven’t looked back since.  It took me less than half an hour to get everything up and running with my Windows install, and I haven’t had any issues with it at all.

I think at some point I will probably explore Linux again, as it really did have some decent selling points.  However, it’s just lacking way too much polish for me to be able to move over to it wholesale as my primary OS, and I definitely wouldn’t move over to it if I was doing anything in production, yet.  That’s just me, and my relative inexperience with it, but it’s still enough to keep me away from it for a bit.

Want to know about Regular Expressions in Java? Read this…

Here’s a nice little guide over at ocpsoft by Lincoln Baxter III.  I don’t have a huge use for these in my current job, but they’re fun to play around with, and actually pretty useful if you’re doing something other than just math in your classes.

Beats by Streets!

As if Rod Streeter wasn’t bad-ass enough already, I present you :

Reading a Rainforest Automation EAGLE with a Jace

I’ve always been concerned about utility use in my house.  With a wife and a couple of young boys, keeping our utility bills under control can be a challenging task.  I’ve put together a few projects in the past to help monitor our consumption as it’s happening, and they’ve generally helped identify energy hogs and bad practices in my house.  The solutions I’ve come up with in the past were fairly rudimentary, and weren’t easy for my family to read.  I wished there was a simpler way to read the consumption information off the shiny new “smart” meter that our friends at our local utility installed.  It collects a bunch of really cool data that they let me access the next day or so on their website, but that doesn’t help me identify problems that are happening right now.  If only there was a way we could pull that information in near real-time, we could do some really neat stuff with that.

Enter the Rainforest Automation EAGLE.  What a cool little device!  It communicates directly with the main electric meter at my house via ZigBee, and pulls off the one thing that was of real interest to me – current demand.  The folks over at Rainforest make several different devices that help accomplish this, but the Eagle was the one that interested me the most.  It’s a stand-alone device, and they have an API that lets me pull basically whatever data they get off of my meter into whatever I want.  I won’t go into the minutia of how to set the device up – the Rainforest documentation is more than adequate for that – but I will tell you the whole process took less than 10 minutes.  If you’re interested in monitoring your demand, and you’re lucky enough to live in one of the areas served by the utilities that support this device, I highly recommend you pick one of these bad-boys up.

Once I had the Eagle up and running, it took a little bit of work to get the data from the device into the Jace I have at my house.  I am working on getting all my utility information collected using the Jace so that I can eventually build a portal for my house that I can use to do all my monitoring and control.  This was the first device that I started reading via the Jace, and it was simple to get up and running.  The Eagle reports using a simple XML structure that can be accessed through a few different methods, all of which are published on the Rainforest Automation site.  It’s easily read using the simple Niagara XML parser.  The great thing about reading this data into the Jace is that we can then perform other calculations and store our data using the capabilities already present in the Niagara platform.  Right now I’m only trending  the current consumption data, as I have been buried in other projects at work and haven’t had any free time to really dig into what I can do with the Eagle.

I’ve done some rough comparisons between what the Eagle is telling me the meter is seeing, and what my e-Monitor is reporting, and the good news is they’re usually reading within a few percent of each other.  Since the e-Monitor averages its readings and the Eagle output is real-time, it’s expected that they’d be slightly different.

If you want to use the code here in your own Jace, you’ll have to create the program object, change the IP it looks at, and make sure you create the necessary slots as well.  Here’s a screenshot of the Slots tab so you can duplicate it.

Slot Tab

The only thing I’ve had a problem with so far is that the query occasionally hangs up – I’m not exactly sure why.  I inserted a check into the program to try to force a re-query, but apparently that’s not bulletproof.  I’ll put a little more effort into it when I get some free time.  For now, here’s the code, feel free to use it and let me know if you see where my hang up is.

Program Code

 

 

Creating .csv Files in Niagara AX

I recently had the need to create .csv files to store array data in the file space of a Jace.  The application required that I create the file if it didn’t exist, and if it did exist, read the data that was there.  I also needed to save the array values to the .csv file on station shutdown, and at other intervals depending on if the Jace was a ‘hard’ Jace or a ‘soft’ Jace.  Because the memory used for the file space has a limited number of cycles, it was suggested that I not write to that space more than once a day if necessary, so that’s why the different flavors of Jaces have different write periods.

After digging around on Niagara Central and sorting through the API it wasn’t too difficult to put together.  Here’s some snippets of the code, and explanations of what each part does.  This should hopefully get you rolling in the right direction if you have need for implementing something like this.

For the first part, I create the array that I’m going to read / write, and then assign a value to an integer to determine what ‘period’ I am in – for this application I am recording 10 values of 15 minute interval data, hence the 96 rows ( 24 * 4 ) and 10 columns. The first step to creating the file is to create a FilePath object, named fp here. From there, I have a couple of other booleans that determine if I’ve completed certain functions in my class.


double[][] results = new double[96][10];

int lastPeriod = determinePeriod();

FilePath fp;

/* Determine if this is installed on a Soft Jace or a Hard Jace.
* We only want to write to the non-temporary file space on a Hard
* Jace once a day. Using these booleans, we will determine what
* type of device the program is installed on. If installed on a
* Soft Jace, the .csv file will be updated every time the array
* is updated, every midnight, and when the station is shut down.
* If installed on a Hard Jace the .csv file will only be updated
* on station shutdown or at midnight if the station is operating.
*/

boolean isSoftJace = checkDeviceType();
boolean fileWritten = false;

The next important part comes in the onStart() method, or started() if you’re building a module. The basics of this part is that I wanted to create a unique name for each input that I was monitoring, and store each inputs .csv file in a base ‘Arrays’ directory under the file space. I also wanted to organize the input .csv files by the associated equipment. To do that, I determined the name of the program, and the name of the parent of the program, and used those to build a string that I used to create the filepath. From there, I assigned a value to the previously created fp object using the factory method for creating FilePath objects, which is simply just giving it a String value that represents the actual file path that you want to use to read / write to.

After I’ve created the FilePath, I call methods that check if the file currently exists, and if it doesn’t, creates it. After that, I read the values from my file into my array. My file creation method simply writes values of zero to all the expected positions if the file doesn’t exist.

  String name = getProgram().getDisplayName(null);

  String parent = getProgram().getParent().getDisplayName(null);

  // File path using station home as root - Defined here

  fp = new FilePath("Arrays/" + parent + "/" + name + ".csv");

  checkFileExists();

  readArray();

The checkFileExists() method is fairly basic. The method returns a boolean value for use by other methods in my program. To check if the file exists, you simply make a BIFile object, and pass the FilePath object to it. If the file exists, the file object will be non-null. So I check for this, if the file object is null, I call the createFile() method and return a ‘false’. If the file exists, I simple return a ‘true’.

private boolean checkFileExists() {

  boolean fileExists = true;

  // Make a BIFile out of the FilePath

  BIFile file = BFileSystem.INSTANCE.findFile(fp);

  // Determine if the file exists, if it does not, create it.

  if ( file == null ) {

    createFile();

    fileExists = false;
  }

  return fileExists;
}

For all the file I/O, I utilize threads to make sure I don’t kill the watchdog timer. From what I’ve gathered, this is a good practice any time you are reading or writing to a disk, as the operation is relatively slow.

/* The createFile() writeArray() and readArray() methods all create threads
 * for accessing the file system. This is done by creating inner classes
 * and utilizing the run() method implemented by the Runnable interface.
 * This prevents any delays while reading or writing to the disk from
 * impacting the main thread and possibly bombing out the watchdog timer.
 */

private void createFile() {

  Thread createArray = new CreateFile();

  createArray.start();
}

private void writeArray() {

  Thread writeArray = new WriteFile();

  writeArray.start();
}

private void readArray() {

  Thread readArray = new ReadFile();

  readArray.start();
}

The createFile() method is pretty straightforward. I use an OutputStream and a PrintWriter to write the file. You can use a StringBuilder object or any number of ways to make your string, and then you just pass it to your PrintWriter to write it to disk. For my application, I looped through the 96 rows, and had an inner loop that wrote 10 zero’s to populate my array. Do as you need to build your file.

class CreateFile extends Thread {

  public void run() {

    try {

      // Make a BIFile out of the FilePath

      BIFile file = BFileSystem.INSTANCE.makeFile(fp);

      // Now we initialize the files contents with 96 periods with
      // 10 data periods each

      OutputStream outputStream = file.getOutputStream();

      PrintWriter out = new PrintWriter(outputStream, false);

      String content = "";

      ** BUILD YOUR STRING HERE THAT YOU WANT TO WRITE.**

      out.println(content);

      out.close();
    }
    catch (IOException ioe) {

    }
  }
}

Reading the file is essentially the same operation, only I’m populating the array values instead of writing from the array. I created an array of String objects and just iterated over them to get the values that I wanted out of them, and then wrote them to my array.

class ReadFile extends Thread {

public void run() {

  // Create a BIFile out of the passed in FilePath

  BIFile file = BFileSystem.INSTANCE.findFile(fp);

  try {

    // Convert the BIFile to an array of Strings per line

    String[] lines = FileUtil.readLines(file);

    // Iterate through the array of Strings

    for ( int i = 0; i < lines.length; i++ ) {

      // Convert the current String to it's component parts by splitting
      // at each comma

      String[] resultsOfCurrentLine = TextUtil.split(lines[i], ',');

      // Iterate through the array of values returned from splitting
      // each line, and convert the values to doubles

      for ( int j = 0; j < resultsOfCurrentLine.length; j++ ) {

        results[i][j] = Double.parseDouble(resultsOfCurrentLine[j]);
      }
    }
  }
  catch (IOException ioe) {

  }
}

Writing the file once it’s created is also fairly straightforward.

class WriteFile extends Thread {

  public void run() {

    boolean fileExists = checkFileExists();

    if ( fileExists ) {

      try {

        BIFile file = BFileSystem.INSTANCE.findFile(fp);

        OutputStream outputStream = file.getOutputStream();

        PrintWriter out = new PrintWriter(outputStream, false);

        // Loop through all the periods

        for ( int i = 0; i < results.length; i++ ) {

          String content = "";

          for ( int j = 0; j < 10; j++ ) {

            content += results[i][j];

            if ( j < 9 ) content += ",";
          }

          out.println(content);
        }

        out.close();
      }
      catch (IOException ioe) {

      }
    }
  }
}

The only other part that’s interesting is how to determine if you’re utilizing a hard Jace or a soft Jace. I haven’t tested this method fully, but the quick test I did seemed to work. The hard jaces use QNX, so it’s fairly easy to figure this one out.

private boolean checkDeviceType() {

  BComponent sys = (BComponent)BOrd.make("service:platform:SystemPlatformService").get();

  sys.lease();

  BString osName = (BString)sys.get("osName");

  boolean isJace = osName.toString().startsWith("qnx");

  return !isJace;
}

There’s quite a bit of helpful information on this on Niagara Central. If you’re looking for more help, search for “Create a BIFile” That’s where I pulled a lot of this stuff from.  It’s located here : <a title=”How to create a BIFile” href=”http://www.niagara-central.com/ord?portal:/dev/wiki/How-To_Create_a_BIFile” target=”_blank”>Create a BIFile</a>

The only other challenging part is figuring out how you are going to structure your file, and how you’re going to parse the data that you have in your array.  But that’s usually just simple loops, so it shouldn’t be too difficult.  If you need any examples, please shoot me an e-mail and I’ll see what I can throw your way.

Welcome to the new digs…

You may have noticed things look a little different here right now, and that pretty much all of my content is gone.  I recently moved and because my new internet provider, while being literally twice as expensive for the exact same service I was receiving before, has decided that it’s in my best interest that they block any outbound traffic on port 80, basically forcing me to host my sites elsewhere.  While there are work-arounds for not being able to send stuff out on 80, none of them really jive with how I have things set up, and I wasn’t really in to doing something half-assed, so I signed up with a hosting provider and will move my stuff over to it over the coming week or so.

So, thanks, Cox Communicaitons, for being twice as expensive, and providing half the service that Time Warner did.  You’re awesome.  And thanks to AT&T for not being able to provide anything faster than old school DSL speeds to my house, even though you constantly bombard me with advertisements telling me how awesome your fiber build-out turd that you call U-verse is.  You would think that they would have put a little more thought into building out their plant in a brand new neighborhood, and that they’d at least be able to offer something near what they could on their plant at my old house – where the copper coming in was 40 years old.

Damnit Google / Verizon FiOS, where are you?