Initial Thoughts: Raspberry Pi 2 and Windows IoT Core

Over the past week I’ve been taking a look at Windows IoT Core running on a Raspberry Pi 2. Windows IoT Core is a powerful new operating system from Microsoft that currently runs on the ARM-based Raspberry Pi 2 and the Intel-powered, x86-based MinnowBoard Max.

Until now, the Raspberry Pi has mostly run a collection of Linux-based operating systems. Microsoft, as part of their recent push into the IoT market, is looking to change this by releasing a version of Windows that runs on these more resource-constrained devices. The result is Windows IoT Core, a surprisingly strong first step into a segment previously dominated by Linux.

In this post I’ll be taking a look at the Raspberry Pi 2’s hardware, followed by an overview of Windows IoT Core. At the end I’ll show a sample project that integrates with and enables the use of Netduino Go modules with this new platform.

Continue reading Initial Thoughts: Raspberry Pi 2 and Windows IoT Core

MicroTweet 2

Back in 2011 I released a Twitter OAuth API client library for the .NET Micro Framework called MicroTweet. Here’s the original blog post about it.

A lot has changed since then: most notably, Twitter deprecated and disabled their v1.0 API and started enforcing the use of SSL connections to access API endpoints. These changes meant that the original MicroTweet library hasn’t worked for quite some time (sorry!).

After receiving my Netduino 3 Wi-Fi (which features built-in SSL support) I thought it might be interesting to revisit this library and update it to work with Twitter’s new API requirements.

The result is MicroTweet 2 — now available on GitHub and as a binary package on NuGet.

In this post I’ll go over some of the changes to the library and its development process.

Continue reading MicroTweet 2

GoBus: An Alternate Approach

When I first received the new Netduino 3 Wi-Fi I was very eager to test its GoBus functionality. There was one problem, though: the firmware it was running didn’t include the library needed for GoBus to work.

This gave me a chance to reimagine how GoBus could be implemented. I started thinking about a new, more flexible architecture that enabled complete customization while still remaining simple and easy-to-use.

I ended up implementing these ideas in an experimental GoBus library that, for the moment, I’m calling GoBusExperimental. (Catchy, I know.)

In this post I’ll start by going over my goals and some of the implementation details. If you’re just here for the cool pictures and experiments (I can’t blame you!) scroll down to the Customization section to see some of the things this library enables.

It’s important to note that everything in this library should be considered experimental. I haven’t spent much time implementing and organizing/thinking about this approach and it definitely shouldn’t be considered “final” in any way. I’m definitely open to hear suggestions for changes and improvements as well.

Continue reading GoBus: An Alternate Approach

Netduino 3 Wi-Fi Review

Two new Netduinos were announced today: the Netduino 3 Wi-Fi and the Netduino 3 Ethernet! The Wi-Fi version ships today, and the Ethernet version is scheduled to ship in late June now shipping! You can view Chris Walker’s announcement post on the Netduino forums here.

Update, August 8, 2015: The Netduino 3 Ethernet is now shipping (forum thread here). Also available is the Netduino 3 (base model, no networking). The forum thread for the base Netduino 3 is here.

I’ve been testing the Netduino 3 Wi-Fi for the past few weeks and I can easily say it’s the best Netduino hardware ever released. This board is awesome.

There are two huge differences with this model compared to the previous Netduino Plus 2: the Ethernet port has been replaced with Wi-Fi (2.4GHz 802.11b/g/n via TI’s CC3100) and three GoBus ports have been added along the right edge of the board. Even with these additions the board is still very small — only about half an inch wider than the NP2.

With the Netduino 3 Wi-Fi you get everything you’ve come to expect from a Netduino: most notably, beautifully crafted hardware with features to match.

Continue reading Netduino 3 Wi-Fi Review

Managing XAML Resources in Universal Windows Phone 8.1 and Windows 8.1 Apps

Universal apps for Windows 8.1 and Windows Phone 8.1 allow you to share both code and XAML resources between desktop and phone versions of an application. Anything contained in the “Shared” pseudo-project gets compiled individually into each platform-specific project:

universalsolution

This is unlike Portable Class Libraries where a single assembly is compiled and shared between the projects that use it. Files in the “Shared” project are included and compiled directly alongside the platform-specific projects’ own files.

This enables some nice features. For instance, you can write conditional code blocks (using #if) to change application behavior between different platforms. New Universal apps have the WINDOWS_PHONE_APP and WINDOWS_APP symbols defined for this purpose:

Sharing XAML Resources

XAML resources are a bit different. It isn’t currently possible to have conditional XAML within a single file (although there is at least one effort being made toward that goal), so you either have to share the entire file or make a separate copy for each platform.

If you want to define app-wide XAML resources (outside of the context of a particular page or control) you might typically do that in App.xaml. But if you share App.xaml/App.xaml.cs between both the phone and desktop platforms (and you should!) then it becomes impossible to have different app-wide XAML resources on each platform.

Merged ResourceDictionaries

You can work around this issue by merging in platform-specific ResourceDictionaries within App.xaml:

In this example, the app will look for a file called Themes/AppResources.xaml and merge it into its main ResourceDictionary. This file could be either a shared or platform-specific file, and you can specify additional ResourceDictionaries to merge in as well. (This can get a bit tricky, however, if you need to reference static resources across different merged files, so it’s usually best to try to keep things contained in a single file if possible.)

For our needs, we’ll simply add a new Resource Dictionary with the specified name in each project. (Also, it’s worth noting that Resource Dictionary is now included in the list of file templates within Visual Studio, making this even easier.)

Here’s what the VS solution looks like with the platform-specific XAML resource dictionaries underlined in red:

universal-xamlresourcesFrom there, just put any XAML resources you need in the platform-specific AppResources.xaml file and they will become available throughout your application. Any styles or other resources will work in the Visual Studio designer window and the new XAML static resource autocompletion will continue to work exactly as you’d expect.

Easier Page and User Control Sharing

This also makes it easier to share pages and user controls between platforms.  You can reference platform-specific styles, DataTemplates, or any other static resource from shared pages/controls as long as a resource exists with the same name on each platform.

In most situations, this will probably be a better solution than modifying control properties from conditional code in the code behind. Not only does it help maintain the separation of code and layout, but it also works perfectly within the Visual Studio designer.

Here’s an example with a shared page. The style MyTextBlockStyle sets the text color to red on Windows Phone and green on Windows. (By the way, you can switch between viewing within the context of Windows or Windows Phone by using the drop-down box I’ve underlined in red.)

Windows Phone:

sharedpage-wp

Windows:

sharedpage-win

Finding Default Styles for Windows Phone 8.1 and Windows 8.1 XAML Controls

When you want to retemplate a XAML control, you can usually create a copy of its default template by right clicking the control within the Visual Studio Designer or Document Outline windows and selecting “Edit Template” or “Edit Additional Templates”:

xaml-edittemplatecopy

Clicking “Edit a Copy…” will allow you to name the new style and select where you want to put it. Visual Studio will copy over the default properties and point your control to use the new style.

In some situations, it may be difficult or impossible to select the control you wish to edit through the designer. Or, such as with this ContentDialog control, the option may be disabled:

xaml-edittemplatedisabled

For those situations, you can find the default styles for all Windows Phone 8.1 XAML controls in the following file:

The equivalent file for Windows 8.1 XAML controls is located at:

From there, you can copy the styles and templates you need into your app and modify them as necessary.

Eat What You Like, but Less Of It

If I were to write a diet book, that would be the title.

One year ago today I started tracking my weight. I had been overweight for a long time, but I had never made any serious effort to do anything about it. I actually didn’t even know how much I weighed.

Now, one year later, I’ve lost 70 pounds, I’m well within the “normal” BMI range for my height, and I feel better (both physically and psychologically) than I have in years.

A lot of people ask me how I did it or what my secret was. The truth is, there is no trick, and you probably already know the answer: diet and occasional exercise. That’s it.

I never knew how easy this could be. My whole life I believed it would take more effort than it actually did. I think a lot of people have these same misconceptions.

But there are a few things I learned along the way that helped me stay motivated. These changes have made a huge improvement in my quality of life and I hope by sharing my experiences I can inspire others to do the same.

Note: These are just my personal experiences of what worked for me. Different things work for different people, and what worked for me may not work for you. This is not medical advice. Consider talking to your doctor before starting a new diet plan.

Continue reading Eat What You Like, but Less Of It

The Importance of Using a Reputable Web Hosting Company

PHP allows you to execute arbitrary external programs using exec. This is great for when you need to do something beyond what is possible to do with PHP alone.

For instance, let’s say you needed to do some PDF manipulation. You might find that a program like QPDF suits your needs. If you install QPDF on your server you can call it from PHP simply by using exec. For example:

The Inaccessible VPS

I’ve recently been developing a web application for a client that involves a lot of custom PDF processing. At this moment, we’re using three different PDF manipulation libraries/programs to fulfill the needs of this site. Unfortunately, there is no single PDF library that handles all of our needs for this application.

Thankfully, the client has elected to use a VPS. The great thing about using a VPS is it gives you full control over the entire server, allowing maximum flexibility to use any third-party libraries we need.

Unfortunately, however, the client chose to use the same company they purchased their domain name from as their VPS provider.  You might know them from their Super Bowl ads. Or their support of SOPA. Or that time their CEO shot and killed an elephant. Or perhaps one of the other controversies they’ve been involved in.

The client also chose the $129.99/month “assisted service plan” which removes root access to the server in exchange for allowing the company’s “expert staff” (more on them later) to manage it on your behalf. You can’t even access the server via SSH. Instead, you are given access to a Plesk control panel, but you don’t even get full access to that — most of the interesting settings are locked out.

So one of the major reasons for picking a VPS — direct, unrestricted control — isn’t even available.

“Expert Staff”

Ok, so, giving them the benefit of the doubt, maybe dealing with support every time you need to run a command on the server isn’t so bad (bear with me here). Maybe we can even forgive the minimum 24-72 hour turnaround time (longer than any host I’ve ever dealt with) as long as they do what you need.

PHP’s exec was disabled by default, but they enabled it for us. Great. We asked to have PDFtk installed, they installed it. Well, first they told us they couldn’t install it because it’s a Windows program (all you have to do is scroll a bit to see the Linux version). Not exactly confidence-inspiring, but after getting our support request escalated and pointing out the Linux version, a few days later, we had it up and running.

We later found that we would need QPDF as well to unlock encrypted PDFs. (PDFtk can do this too, but, unlike QPDF, it requires the original encryption password.) So we submitted another support ticket. While they did at least recognize QPDF is available for Linux, they refused to install it because “we can’t install any application that require [sic] us to compile it on the server.”

Of course, QPDF binaries are available from a number of places. This is a CentOS 6 server, and QPDF can even be installed directly from the EPEL repository.

Breaking New Ground

Sadly, supplying ready-to-install binaries still wouldn’t be enough to convince support to install QPDF.

At this point you might be wondering why we hadn’t already moved to another host, and, indeed, if it were up to me, we would have moved this site long before this set of issues. Unfortunately it isn’t up to me, and the client still wants to use the original VPS. I suspect it’s because they agreed to a one or two-year contract with this provider.

Anyway, back to QPDF. Support replied saying they still couldn’t install it because, while they were able to find documentation showing examples of using PDFtk from a web application (presumably using a wrapper such as this), they couldn’t find any documentation that indicated QPDF could be used in the same way. Evidently nobody has ever called QPDF from PHP before (or, more likely, it’s just that nobody has posted PHP examples of it because of how trivial it is to use via exec).

So that is the reason for this post: to provide public documentation showing how QPDF could conceivably be used from a web application. It’s apparently impossible to program anything without ready-to-go examples from documentation, blog posts, or Stack Overflow.

Don’t Do This

Seriously. Use a reputable web hosting company. Web hosting is a horrible business, but, at the very least, you can save yourself a lot of headaches by not buying it from the long list of “services” your domain registrar tries to sell you during checkout.

I used Liquid Web for nearly 10 years and, even with managed servers, I’ve never had to try to convince them to install something. They’re not scared to give you root access. Even when I would screw something up, they were always happy to help, and even explain the steps they took to fix it.

I’ve recently started moving some sites to Linode. I haven’t had to use their support yet, but even if you choose their paid managed support, you still retain root access to your servers.

If nothing else, if you’re hosting something big enough to need a VPS, at least make sure you have root access. That way, if support turns out to be incompetent, you can at least go in and fix things yourself.

Update: QPDF has been installed! Total time from first request: 15 days.

Fixing jumpy ListBox scrolling in WP7 Mango

Update October 14, 2011: If you are using Buttons in your item templates this may cause some issues. See the comments at the bottom of the page for more information and a potential workaround.

A few days ago I tweeted about a ListBox scrolling issue I found with WP7 Mango when using item templates that have different heights. I first noticed this issue when using the Silverlight Toolkit’s LongListSelector control, but I found that it also applies to the standard ListBox control (which the Mango version of the Silverlight Toolkit uses internally to display data) whenever list items have different heights (e.g., wrapped text, list headers/footers, etc.).

In short, the issue is that after tapping/selecting an item in the list, scrolling becomes extremely jumpy. It’s a bit hard to describe — it’s not just a matter of poor performance, the list scroll position will actually jump up or down as you try to scroll through the list.

I found a relevant bug report on the SL Toolkit’s issue tracker here. At first I thought the issue was caused by selecting an item within the ListBox but I found that deselecting the item didn’t fix the scrolling behavior.

After doing some further testing I discovered that the issue was triggered whenever the ListBox (or a control displayed within the ListBox) gained focus. Setting focus to another control on the page seems to fix the issue completely.
Continue reading Fixing jumpy ListBox scrolling in WP7 Mango

Using remote images with secondary live tiles in WP7 Mango

I’ve seen a few posts on Twitter and this blog post by Jeff Wilcox about the issues with using a remote image on secondary live tiles, so I thought it might be useful to share the workaround I developed for a new WP7 application I have been working on that makes heavy use of secondary tiles.

In short, the issue with using remote URIs for the BackgroundImage or BackBackgroundImage properties of secondary live tiles is that the tiles will disappear after restarting the phone. Worse, the tile still appears in the ShellTile.ActiveTiles list as though the tile is still pinned. This issue is mentioned in a few parts of the documentation, including here:

When creating a secondary Tile, the BackgroundImage and the BackBackgroundImage images must be created using a local resource.

I did some testing and determined that the issue is only caused by using a remote image URI during the initial tile creation — any tile updates that occur later on can use remote URIs without any trouble. In fact, you can update the tile with a remote URI immediately after creating it and the tile will still appear after the phone is restarted. (Note that the image displayed after a restart will be the static, local image and not the remote image. For my app, the tiles are regularly updated via push notifications but you could also update the tiles from within your app or background agent, etc.)
Continue reading Using remote images with secondary live tiles in WP7 Mango