My First Netduino Go Project

Add Comment | Apr 28, 2013

Earlier I wrote that I got a Netduino Go Starter kit for Christmas. I've worked with it from time to time. This is a little late posting, because I finished my first project in February. I thought I'd share it here and perhaps I might get some ideas for future projects.

You get several things with the starter kit including an RGB LED, button, and potentiometer. I put these together as an RGB flasher. The concept is simple. The LED flashes with color changes on an interval. The button starts and stops the flashing. And the potentiometer controls the rate of the flashing.

To start this I created a class with the following interface (full class code at the end of the article):

class RgbFlasher : IDisposable {
     RgbFlasher()
     Start()
     Dispose()
}

This class pretty much controls everything. The Main method creates and starts a RgbFlasher and waits as shown below.

 public static void Main()
 {
     var flasher = new RgbFlasher();
     flasher.Start();

     while (true)
     {
         Thread.Sleep(1000);
     }
 }

Overall, it was a fun, short project and was easy to put together. I'm looking for a little more of a challenge the next time around.

Full listing for the RgbFlasher class

using NetduinoGo;
using System;
using System.Threading;

 

public class RgbFlasher : IDisposable
{
    private readonly RgbLed rgbBtn;
    private readonly Button toggleBtn;
    private readonly Potentiometer delayMeter;
    private Timer timer;

    private readonly Random rand;
    private bool isFlashing = false;

    private const int DelayBase = 1750;
    private const int DelayMin = 250;

    public RgbFlasher()
    {
        // init components
        rgbBtn = new RgbLed();
        delayMeter = new Potentiometer();
        toggleBtn = new Button();
        toggleBtn.ButtonPressed += (sender, state) => isFlashing = !isFlashing;

        rand = new Random((int)DateTime.Today.Ticks);
    }

    public void Start()
    {
        int delay = GetDelay(delayMeter);
        timer = new Timer(new TimerCallback(Flash), null, 0, delay);
    }

    private void Flash(object state)
    {
        // change the color while led state is flashing; button
        // controls that state
        if (isFlashing)
        {
            byte r = (byte)rand.Next(255);
            byte g = (byte)rand.Next(255);
            byte b = (byte)rand.Next(255);

            rgbBtn.SetColor(r, g, b);
        }

        // set the timer based on the potentiometer
        int newDelay = GetDelay(delayMeter);
        timer.Change(newDelay, newDelay);
    }

    private static int GetDelay(Potentiometer meter)
    {
        return (int)(DelayBase * meter.GetValue()) + DelayMin;
    }

    public void Dispose()
    {
        if (rgbBtn != null) rgbBtn.Dispose();
        if (toggleBtn != null) toggleBtn.Dispose();
        if (delayMeter != null) delayMeter.Dispose();
        if (timer != null) timer.Dispose();
    }
}

HTTP Succinctly

Add Comment | Mar 10, 2013

I was approached recently by Syncfusion. They pitched their Succinctly series and requested that I write about one of the e-books in the series. I chose HTTP Succinctly. My familiarity with the topic gave me the perspective needed to determine if their series lives up to its name.

The Succinctly series was born out of a desire to provide concise education on technical topics for developers. The series includes e-books on data structures, HTTP, Git, Lightswitch, and various languages. Syncfusion claims that they can get you up and running on a technology in “about the time it takes to drink a few cups of coffee.”

This claim is not far off the mark. I read through the Kindle version of HTTP Succinctly quickly (it’s also available in PDF format). The writing is good quality and interesting. Each e-book in the series is written by an expert in the field, so I expect nothing less. The HTTP e-book is broken out into five chapters that are well organized and build logically from those preceding. I was pleased that the Kindle format included a properly formatted table of contents. Headings and paragraph layout are spot on; and images are displayed properly with the text. This is not a sloppy port that I see in so many e-books.

The e-book starts with a discussion on what resources are in the context of HTTP. That leads right into the topic and chapter on messages. This is by far the best, and what I’d consider the main chapter in the book. Don’t get me wrong the following chapters on connections, web architecture, and state and security are all critical to the discussion. It’s just that for me the messages chapter is the meat. I will give an honorable mention to the discussion on protocol layers in the connections chapter.

It’s rare for me to review something and not have a coherent complaint. I was set to complain about the lack of information on the other protocol layers before it dawned on me that it wouldn’t be fair. My complaint would’ve been foolish, because the author stuck to the rule about being concise. HTTP is just one of the layers. It makes me wonder how much time I’ve wasted reading filler material in scores of other programming books.

HTTP Succinctly does a great job of providing a foundational understanding of HTTP. It focuses nicely on what developers need to understand about the technology. It may not answer every question about HTTP, but you won’t stumble around searching the Internet after you read this e-book and you won’t waste a copious amount of time reading several hundred pages. I believe this e-book will demystify the HTTP protocol for the newcomer; and may clear up misconceptions for the experienced. I’m excited to read another e-book in the series.

I was compensated for this review. However, Syncfusion didn’t influence the topic, content, or my opinions in any way.

Why I’m Not Buying a Surface Tablet

Add Comment | Feb 17, 2013

I’ve been anticipating the launch of the Microsoft Surface tablet since it was first announced. Unfortunately, I was let down and had to wait longer when the release announcement for the RT was made. It meant several more months to wait for the Surface Pro which would run the applications I need and want to run. I need a computer and not just a toy. An Apple iPad would be sufficient if a toy was what I wanted.

At that time not buying a Surface wasn’t a consideration. But, doubt crept in over time as can happen. I didn’t really pay too much attention to the launch of the Surface RT. Though, I remember hearing enough negativity to give me pause. And I was still a little sore about having to wait so much longer. And as it turns out the Pro wasn’t really worth the wait.

Let me clarify that before the hate mail starts pouring in. There’s plenty to like about the Surface Pro. However, this is not a review it’s a discussion on why I didn’t buy it. I spent a good deal of time playing with it at my local store. It’s certainly heavy and I think it would be uncomfortable holding it in one hand for a long period of time. But, giving what it does I feel it’s acceptable. I wish I would have been able to spend time with the digitizer pen, but my local store didn’t have one included with the display model. They don’t even carry the 128GB model. Those are two facts, not to mention general availability, that saved me from an impulse buy.

One of the major things I heard mentioned was the remaining storage space available. That wasn’t a factor for me, because I know the number is more marketing than anything. ZDNet has a good article that puts the storage space issue into perspective titled, “Surface Pro versus Macbook Air: Who’s being dishonest with storage space?” My reasons for not purchasing a Surface Pro can be stated succinctly, “it’s all about the battery.”

The first review I read indicated the battery life to be somewhere in the neighborhood of five hours. Not good. But, not terrible considering the capabilities of the tablet. The drain demonstrated by the demo model I used at my local store seemed to indicate that I would get more like four and half hours. I had to consider that the demo was not connected to a network; and I wasn’t doing anything other than watching a few short (less than 30 second) demo videos that would cause excessive drain. I don’t want to know what something like Visual Studio or Photoshop would do for the battery life.

The straw though was the teardown article written by ifixit. The article makes it clear that Microsoft didn’t make a battery change serviceable. This means a $1,000 computer has a planned obsolescence of a couple of years. This is not a couple of hundred dollar toy. I find it very troubling that Microsoft is taking more and more plays out of Apple’s playbook.

There are other things that weighed down on my decision. For instance, the price of the touch pad and application side-loading are important. I could side-load desktop applications on the Surface Pro, but I would need Windows 8 Enterprise to side-load Metro-style applications. That’s not a deal breaker in of itself, because I am an MSDN Premium subscriber. But, it’s indicative of another restriction that stinks a lot like Apple.

I sincerely hope that Microsoft improves the battery life and makes it serviceable (even if that’s a reasonable factory service fee). I will more than likely buy one if they do. I may even buy a Surface RT in the future for my daughter. In my opinion this is another failed launch for a product that had a lot of potential.

Timestamp to String

3 Comments | Jan 05, 2013

The SQL Server TIMESTAMP data type is represented as a byte array in the .NET Framework (byte[] in C#). You may have the need for any number of reasons to provide a representation of the timestamp that can be displayed to the user or for debugging purposes.

This may seem complicated at first glance, but the .NET Framework already includes methods to complete the operation in a few lines of code. The only trick that you need to know is if the helper object treats the bits as big endian or little ending (meaning the array needs to be reversed). There’s a property for that, so it’s not a problem.

private static string TimeStampToString(byte[] tstamp)
{
    var val = GetTimeStampValue(tstamp);
    return "0x" + val.ToString("X").PadLeft(16, '0');
}

private static long GetTimeStampValue(byte[] tstamp)
{
    if (tstamp == null || tstamp.Length == 0)
        throw new ArgumentNullException("tstamp");

    byte[] buffer = new byte[tstamp.Length];
    tstamp.CopyTo(buffer, 0);

    if (BitConverter.IsLittleEndian)
        Array.Reverse(buffer);

    return BitConverter.ToInt64(buffer, 0);
}

You pass the byte array to the TimeStampToString method and you’ll get back a string in the format: 0x0000000000000000. This is the format that you get out of SQL Server Management Studio.

A Look Ahead to 2013

5 Comments | Dec 30, 2012

It’s been a busy holiday season with a couple of flights to visit family. I ended up getting a few interesting tech related gifts this year. First, I’m enjoying a nice new sound system from Cyber Acoustics for my computer from my mother. It’s hard to believe I’ve gone this long with the built-in laptop speakers.

My sister-in-law bought me the book Learn PowerShell 3 in a Month of Lunches. PowerShell is a skill I’ve wanted to pickup for a while. I’ve already dived into the book and it seems pretty thorough on teaching the tool. It doesn’t emphasize scripting, so I may pick something up for that later.

Finally, my dad got me a Netduino Go Starter kit. This is just for fun. I’ve really turned a cold shoulder to hardware in the past, but I’m thinking it’s time to warm up to it a bit. I’ve only had time to set it up and test it really quick, but that went pretty smoothly. The kit didn’t come with any documentation and the online information is a little fractured. However, I managed to create my first program that blinked the power LED in Visual Studio 2012 despite the lack of specific assets like project templates for this version of Visual Studio.

The following is my equivalent of a hello world application for my Netduino Go:

using (var led = new OutputPort(Pins.PowerLed, true))
{
    led.Write(false);

    while (true)
    {
        Thread.Sleep(500);
        led.Write(true);
        Thread.Sleep(500);
        led.Write(false);
    }
}

On the professional front, I am managing a major internal ERP software upgrade. It’s affecting pretty much every software system we have internally. Hardware is affected as well and we’ve already purchased and installed a new Dell 3-2-1 solution. We have most of the servers virtualized at this point. MVC will be a major technology I use for some projects as well WPF as I continue to crawl towards combining some of our more archaic systems.

Don’t Kill the Password

5 Comments | Nov 22, 2012

A week ago Mr. Honan from Wired.com penned an article on security he titled “Kill the Password: Why a String of Characters Can’t Protect Us Anymore.” He asserts that the password is not effective and a new solution is needed. Unfortunately, Mr. Honan was a victim of hacking. As a result he has a victim’s vendetta. His conclusion is ill conceived even though there are smatterings of truth and good advice.

The password is a security barrier much like a lock on your door. In of itself it’s not guaranteeing protection. You can have a good password akin to a steel reinforced door with the best lock money can buy, or you can have a poor password like “password” which is like a sliding lock like on a bathroom stall. But, just like in the real world a lock isn’t always enough.

You can have a lock, security system, video cameras, guard dogs, and even armed security guards; but none of that guarantees your protection. Even top secret government agencies can be breached by someone who is just that good (as dramatized in movies like Mission Impossible). And that’s the crux of it. There are real hackers out there that are that good. Killer coding ninja monkeys do exist!

We still have locks on our doors, because they still serve their role. Passwords are no different. Security doesn’t end with the password. Most people would agree that stuffing your mattress with your life savings isn’t a good idea even if you have the best locks and security system. Most people agree its safest to have the money in a bank. Essentially this is compartmentalization.

Compartmentalization extends to the online world as well. You’re at risk if your online banking accounts are linked to the same account as your social networks. This is especially true if you’re lackadaisical about linking those social networks to outside sources including apps. The object here is to minimize the damage that can be done. An attacker should not be able to get into your bank account, because they breached your Twitter account.

It’s time to prioritize once you’ve compartmentalized. This simply means deciding how much security you want for the different compartments which I’ll call security zones. Social networking applications like Facebook provide a lot of security features. However, security features are almost always a compromise with privacy and convenience. It’s similar to an engineering adage, but in this case it’s security, convenience, and privacy – pick two. For example, you might use a safe instead of bank to store your money, because the convenience of having your money closer or the privacy of not having the bank records is more important than the added security.

The following are lists of security do’s and don’ts (these aren’t meant to be exhaustive and each could be an article in of themselves):

Security Do’s:

  1. Use strong passwords based on a phrase
  2. Use encryption whenever you can (e.g. HTTPS in Facebook)
  3. Use a firewall (and learn to use it properly)
  4. Configure security on your router (including port blocking)
  5. Keep your operating system patched
  6. Make routine backups of important files
  7. Realize that if you’re not paying for it, you’re the product

Security Don’ts

  1. Link accounts if at all possible
  2. Reuse passwords across your security zones
  3. Use real answers for security questions (e.g. mother’s maiden name)
  4. Trust anything you download
  5. Ignore message boxes shown by your system or browser
  6. Forget to test your backups
  7. Share your primary email indiscriminately

Only you can decide your comfort level between convenience, privacy, and security. Attackers are going to find exploits in software. Software is complex and depends on other software. The exploits are the responsibility of the software company. But your security is always your responsibility. Complete security is an illusion. But, there is plenty you can do to minimize the risk online just like you do in the physical world. Be safe and enjoy what the Internet has to offer. I expect passwords to be necessary just as long as locks.